nca.sparse¶
Non-compartmental analysis of sparse and destructive sampling designs.
A preclinical study rarely samples one animal repeatedly: the animal is sacrificed for the sample (a destructive design, one sample per animal) or contributes a few samples out of the schedule (a batch design). There is no curve per animal then, only a mean curve over the animals of every time point, and the question is how uncertain the area under that mean curve is.
Bailer (1988) answers it: the area is a fixed linear combination of the means,
with the trapezoid weights \(w_j\), so its variance follows from the variances of the means. With one sample per animal the means are independent and
Nedelman, Gibiansky and Lau (1995) give the Satterthwaite degrees of freedom of that sum so the area gets a \(t\) interval. Nedelman and Jia (1998) extend the estimator to a batch design, where an animal contributes to several means, and Holder (2001), commenting on that extension, gives the variance which carries the covariance between the time points an animal is shared by.
pkpdutils computes all three from one identity. Writing the estimator per
animal rather than per time point,
where \(T_i\) are the times animal \(i\) was sampled at, the animals are independent whatever the design, so the variance is the sum over the animals and is estimated batch by batch (a batch is a group of animals with the same sampling times):
With one sample per animal a batch is one time point, \(A_i = (w_j/n_j) y_{ij}\) and \(c_b = w_j^2 s_j^2 / n_j\): the formula of Bailer and the degrees of freedom of Nedelman, Gibiansky and Lau, exactly. With several samples per animal the sample variance of the \(A_i\) carries the covariances of Holder without ever forming them.
Nominal times are used, never the actual sampling times: a mean over animals only exists at a nominal time (the caution of Phoenix WinNonlin for its sparse models).
trapezoid_weights
¶
Weights of the linear trapezoid rule over a grid of times.
The area under the polygon through \((t_j, y_j)\) is \(\sum_j w_j y_j\) with
which is the form Bailer (1988) needs: the area is linear in the values, so
its variance follows from theirs. The logarithmic trapezoid rules of
pkpdutils.nca.options.AUCMethod are not linear in the values and have no
such weights.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
times
|
ndarray
|
the sampling times, strictly increasing, at least two. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
One weight per time, of the shape of |
point_statistics
¶
Count, mean and standard deviation of every time point of a sparse design.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
ndarray
|
the values |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The number of animals sampled at every time, the mean over them and |
ndarray
|
their standard deviation ( |
area_window
¶
The nominal times auc_last of a sparse design covers.
The observed time points up to the last one whose mean is positive, the
\(t_\mathrm{last}\) rule of a concentration curve read on the mean curve.
nca_sparse weights these points and pkpdutils.plot.plot_sparse shades
them, so both read the window from here.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
observed
|
ndarray
|
whether a nominal time carries a sample at all. |
required |
mean
|
ndarray
|
the mean of every nominal time, |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The boolean mask of the covered time points; all |
ndarray
|
is positive. |
bailer_variance
¶
Variance of the sparse area estimate and its Satterthwaite degrees of freedom.
The estimate is written per animal, \(A_i = \sum_{j \in T_i} (w_j/n_j) y_{ij}\) with \(n_j\) the number of animals sampled at time \(j\), so that the animals are independent whatever the design and
where a batch \(b\) is the group of the \(m_b\) animals with the same sampling times and \(s^2_{A,b}\) the sample variance of their \(A_i\). With one sample per animal a batch is one time point and the two formulas are \(\sum_j w_j^2 s_j^2/n_j\) of Bailer (1988) and the degrees of freedom of Nedelman, Gibiansky and Lau (1995); with several samples per animal the sample variance carries the covariance terms of the batch design of Nedelman and Jia (1998) as Holder (2001) writes them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
weights
|
ndarray
|
the weight of every time point, 0 for a time point which is not part of the area. |
required |
values
|
ndarray
|
the values |
required |
Returns:
| Type | Description |
|---|---|
float
|
The variance, the degrees of freedom and the number of batches; the |
float
|
variance and the degrees of freedom are |
int
|
single animal, whose contribution cannot be estimated. |
sparse_mean
¶
sparse_mean(
times,
values,
*,
time_unit,
unit,
dose=None,
substance="substance",
dim="group",
label="mean",
)
The mean curve of a sparse design, with its spread per time point.
The curve every sparse analysis is read from: the mean over the animals
sampled at a nominal time, their standard deviation (ddof=1), the
standard error \(s_j/\sqrt{n_j}\) and the count \(n_j\), each per time
point, so that a time point sampled in fewer animals carries its own count.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
times
|
Any
|
the nominal sampling times, one-dimensional |
required |
values
|
Any
|
the values |
required |
Other Parameters:
| Name | Type | Description |
|---|---|---|
time_unit |
str
|
unit of the times |
unit |
str
|
unit of the values |
dose |
Dose | None
|
the dose of the animals, |
substance |
str
|
name of the substance |
dim |
str
|
name of the sample dimension of the batch |
label |
Any
|
label of the single sample of the batch |
Returns:
| Type | Description |
|---|---|
Timecourses
|
A batch of one sample carrying |
Timecourses
|
point. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the shapes do not fit or the times are not increasing. |
nca_sparse
¶
Non-compartmental analysis of a sparse or destructive sampling design.
The area under the mean curve with the standard error of Bailer (1988), the
degrees of freedom of Nedelman, Gibiansky and Lau (1995) and, for the batch
design of Nedelman and Jia (1998), the covariance of Holder (2001), all
three from the per-animal identity of bailer_variance:
\(t_\mathrm{last}\) is the last nominal time whose mean is positive, as it
is for a concentration curve, and auc_all is the area over every nominal
time with a sample. Both run over the nominal times as they are given, from
the first of them rather than from the dose: nothing is inserted at time 0,
because an inserted point has no variance and the estimator has to stay a
combination of the measured means. A design whose area starts at the dose
carries a nominal time 0 of its own (the value 0 after an extravascular
dose). The peak of the mean curve is cmax at tmax with the
standard error \(s_j/\sqrt{n_j}\) of the mean at that time, the
SE_Cmax of Phoenix WinNonlin. The number of animals behind every time
point is the point variable n_animals.
The estimator is a fixed linear combination of the means, so the weights
are always those of the linear trapezoid rule (trapezoid_weights): a
logarithmic rule is not linear in the values and has no variance formula of
this kind. options.auc_method is therefore not used, and neither are the
rules which read a single curve (lloq, blq, the terminal phase, the
uncertainty of a group curve).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
times
|
Any
|
the nominal sampling times, one-dimensional. Nominal, not actual: a mean over animals only exists at a nominal time. |
required |
values
|
Any
|
the values |
required |
Other Parameters:
| Name | Type | Description |
|---|---|---|
design |
Design
|
|
options |
NCAOptions | None
|
the options, defaults for |
time_unit |
str
|
unit of the times |
unit |
str
|
unit of the values |
dose |
Dose | None
|
the dose of the animals, whose amount travels into the result as
the coordinate |
Returns:
| Type | Description |
|---|---|
NCAResult
|
The parameters of the mean curve without sample dimensions: |
NCAResult
|
|
NCAResult
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
if the shapes do not fit, if the times are not increasing, if the design is unknown or if a serial design holds an animal with several samples. |