nca.terminal¶
Vectorized terminal phase regression.
The elimination rate constant lambda_z is the negative slope of the linear
regression of ln c on t over the points of the terminal phase
(Gabrielsson & Weiner 2016, ch. 2.8; Phoenix WinNonlin NCA). Which points form
the terminal phase is decided by TerminalPhase.method; BEST_FIT evaluates
every window of consecutive points that ends at the last measurable point and
takes the largest adjusted R², preferring more points within a tolerance,
which is the rule of Phoenix.
All windows of all rows are evaluated at once: with suffix sums of x, y,
x², xy and y² over the packed points the statistics of the window
starting at index s are closed-form expressions of the sums from s to the
end, so window_statistics returns (N, n) arrays without a loop over rows
or windows.
TerminalFit
dataclass
¶
TerminalFit(
slope,
intercept,
r2,
r2_adj,
se_slope,
n_points,
t_first,
t_last,
start,
flags,
candidates=None,
)
Result of the terminal regression per row, NaN (and start = -1) without a fit.
Attributes:
| Name | Type | Description |
|---|---|---|
slope |
ndarray
|
slope of |
intercept |
ndarray
|
intercept of the regression, |
r2 |
ndarray
|
coefficient of determination |
r2_adj |
ndarray
|
adjusted coefficient of determination |
se_slope |
ndarray
|
standard error of the slope |
n_points |
ndarray
|
number of points of the regression |
t_first |
ndarray
|
time of the first point of the regression |
t_last |
ndarray
|
time of the last point of the regression |
start |
ndarray
|
packed index of the first point of the window |
flags |
ndarray
|
|
candidates |
DataFrame | None
|
every candidate window of every row with the columns |
window_statistics
¶
Regression statistics of every window from an index to the end of the row.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
regressor |
required |
y
|
ndarray
|
response |
required |
valid
|
ndarray
|
which points enter the regression |
required |
Returns:
| Type | Description |
|---|---|
dict[str, ndarray]
|
Arrays |
dict[str, ndarray]
|
|
dict[str, ndarray]
|
fewer than 3 points are |
terminal_fit
¶
Terminal log-linear regression of every row.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tp
|
ndarray
|
packed times |
required |
cp
|
ndarray
|
packed values |
required |
n_valid
|
ndarray
|
valid points per row |
required |
tmax_idx
|
ndarray
|
packed index of the maximum per row |
required |
phase
|
TerminalPhase
|
the selection rule and its parameters |
required |
manual_mask
|
ndarray | None
|
packed points of the regression for |
None
|
exclude
|
ndarray | None
|
packed points which may not enter the regression |
None
|
windows
|
ndarray | None
|
the terminal window of single rows |
None
|
Returns:
| Type | Description |
|---|---|
TerminalFit
|
The fit per row, with the table of every candidate window |
TerminalFit
|
( |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
candidate_table
¶
Every window the selection of the terminal phase may choose from.
A candidate is a window which starts at a point of the regression, holds at
least phase.min_points regressable points and, with
phase.exclude_cmax, starts after the maximum: the windows BEST_FIT
ranks by the adjusted R², and the same set for the other rules, which pick
one of them by a different criterion. A window whose first point cannot be
regressed is left out, since its statistics are those of the window
starting at the next regressable point (_collect). The slope is reported
as it is, so a window of a still rising curve is in the table with a
positive slope, which BEST_FIT never chooses.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tp
|
ndarray
|
packed times |
required |
y
|
ndarray
|
the logarithms of the values |
required |
regressable
|
ndarray
|
the points which may enter a regression |
required |
tmax_idx
|
ndarray
|
packed index of the maximum per row |
required |
phase
|
TerminalPhase
|
the selection rule and its parameters |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per candidate window with the columns |
DataFrame
|
row of the batch), |
DataFrame
|
window), |
DataFrame
|
are ordered by row and by the start time within a row. |