fit.variability¶
The variability between the subjects of a fit problem and its predictive check.
A fit predicts the data of a mapping with one subject per simulation, the
typical subject of its study group. The subjects of a study differ from it:
Variability declares how, as relative distributions of targets of the model,
e.g. LogNormal(cv=0.3) of a clearance, whose factor has the median 1 and a
coefficient of variation of 30 %. A subject has every target at its factor
times the value its simulation gives the target (the value the experiment
sets for the study group, the value of a fitted parameter or the value of the
model), so the inputs of the study groups stay what they are and the subjects
vary around them (OptimizationProblem.evaluations(..., factors=), see
sbmlsim.simulator.plan.Plan.scaled). The factors are correlated by
Covariances of the targets: a correlation of their normal scores, or the
covariance of the logarithms of log-normal factors (scale="log", the omega
matrix of a population analysis), see sbmlsim.uncertainty.draws. The
studies differ as well, in their populations, assays and protocols:
Variability(between=Variability(...)) is the variability between the
studies, the factors of a study, which all its subjects share and multiply
with their own.
subject_predictions evaluates the mappings of a problem for n subjects of
a variability at one parameter vector. predictive_check nests the subjects
in the parameter vectors it is given, e.g. draws of the uncertainty of the
fitted parameters (uncertainty outside, variability inside), and compares
every observation with the distribution its prediction has over the
subjects: with a variability between the studies the subjects of a vector are
studies studies of n_subjects subjects each. A data point of a group of N subjects (the count of the data
point) is a mean of N subjects, so it is compared with the distribution of
the mean of virtual groups of N subjects drawn from the subjects of a
study (the geometric mean for a mapping of geometric standard
deviations); a data point without a count is one subject. The distributions
of all parameter vectors are pooled, the predictive distribution of the
observation, and its quantiles are the band of a visual predictive check
(Holford 2005; Bergstrand et al. 2011). The share of the observations inside
the outer quantiles is the coverage, about the probability between them for
a model whose variability is that of the data.
Holford N (2005). The visual predictive check: superiority to standard diagnostic (Rorschach) plots. PAGE 14, Abstr 738. Bergstrand M, Hooker AC, Wallin JE, Karlsson MO (2011). Prediction-corrected visual predictive checks for diagnosing nonlinear mixed-effects models. AAPS J 13:143-151.
Variability
dataclass
¶
The variability between the subjects of a fit problem, see the module.
Attributes:
| Name | Type | Description |
|---|---|---|
factors |
Mapping[str, Distribution]
|
target -> the relative distribution of its factor, e.g.
|
covariance |
Sequence[Covariance]
|
the correlations or covariances of the factors, by their targets. |
between |
Variability | None
|
the variability between the studies, whose factors the
subjects of a study share; |
Raises:
| Type | Description |
|---|---|
ValueError
|
for a distribution which is not relative, a covariance of targets which are no factors, or a variability between the studies which has one between its studies. |
all_targets
property
¶
Get the targets of the factors and of the factors between the studies.
draw
¶
Get the factors of n subjects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
the number of subjects. |
required |
seed
|
int
|
the seed. |
required |
design
|
Literal['sobol', 'lhs', 'random']
|
|
'sobol'
|
start
|
int
|
the index of the first subject of the sequence, so that the subjects of several parameter vectors are one sequence. |
0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The factors, |
SubjectPredictions
dataclass
¶
The predictions of the mappings of a problem for subjects of a variability.
Attributes:
| Name | Type | Description |
|---|---|---|
targets |
tuple[str, ...]
|
the targets of the factors. |
factors |
ndarray
|
the factors of every subject, one row per subject and one column per target, the factors of its study included. |
predictions |
Mapping[int, ndarray]
|
the index of a mapping -> its predictions at its data,
one row per subject; |
failed |
int
|
the subjects whose simulation failed. |
study |
Mapping[str, float]
|
the factors of the study of the subjects by target, empty without a variability between the studies. |
PredictiveCheck
dataclass
¶
PredictiveCheck(
quantiles,
n_subjects,
n_vectors,
n_studies,
groups,
seed,
targets,
failed,
points,
subjects,
)
The predictive check of the mappings of a problem, see the module.
Attributes:
| Name | Type | Description |
|---|---|---|
quantiles |
tuple[float, ...]
|
the quantiles of the bands, ascending. |
n_subjects |
int
|
the subjects of every study of a parameter vector. |
n_vectors |
int
|
the parameter vectors. |
n_studies |
int
|
the studies of every parameter vector, 1 without a variability between the studies. |
groups |
int
|
the virtual groups of a data point of a group per study. |
seed |
int
|
the seed of the subjects and the groups. |
targets |
tuple[str, ...]
|
the targets of the variability. |
failed |
int
|
the failed subjects over all parameter vectors. |
points |
DataFrame
|
one row per data point of the checked mappings: |
subjects |
tuple[SubjectPredictions, ...]
|
the predictions of the subjects of every study of every parameter vector, the studies of a vector one after the other. |
coverage_by_mapping
¶
Get the coverage of every mapping.
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per mapping with the columns |
DataFrame
|
|
subject_predictions
¶
subject_predictions(
problem,
x,
variability,
n,
*,
indices=None,
seed,
design="sobol",
start=0,
study=None,
)
Evaluate the mappings of a problem for n subjects of a variability.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
OptimizationProblem
|
the initialized problem. |
required |
x
|
ndarray
|
the values of the parameters in the units of the model. |
required |
variability
|
Variability
|
the variability of the subjects. |
required |
n
|
int
|
the number of subjects. |
required |
indices
|
Sequence[int] | None
|
the indices of the mappings, every mapping by default. |
None
|
seed
|
int
|
the seed of the factors. |
required |
design
|
Literal['sobol', 'lhs', 'random']
|
the design of the factors, see |
'sobol'
|
start
|
int
|
the index of the first subject of the sequence. |
0
|
study
|
Mapping[str, float] | None
|
the factors of the study of the subjects by target, which
multiply the factors of every subject; |
None
|
Returns:
| Type | Description |
|---|---|
SubjectPredictions
|
The factors and the predictions of every subject. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
quantile_column
¶
Get the column of a quantile, e.g. q5 of 0.05 and q2.5 of 0.025.
predictive_check
¶
predictive_check(
problem,
parameters,
variability,
n_subjects,
*,
indices=None,
quantiles=(0.05, 0.5, 0.95),
groups=1000,
seed=None,
design="sobol",
studies=16,
)
Get the predictive check of the mappings of a problem, see the module.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
OptimizationProblem
|
the initialized problem. |
required |
parameters
|
Sequence[ndarray] | ndarray
|
the parameter vectors in the units of the model, one row per vector, e.g. draws of the uncertainty of the fitted parameters; one vector for the variability alone. |
required |
variability
|
Variability
|
the variability of the subjects. |
required |
n_subjects
|
int
|
the subjects of every parameter vector, of every study with a variability between the studies. |
required |
indices
|
Sequence[int] | None
|
the indices of the mappings, every mapping by default. |
None
|
quantiles
|
Sequence[float]
|
the quantiles of the bands, at least two, in |
(0.05, 0.5, 0.95)
|
groups
|
int
|
the virtual groups of a data point of a group per study. |
1000
|
seed
|
int | None
|
the seed, |
None
|
design
|
Literal['sobol', 'lhs', 'random']
|
the design of the factors, see |
'sobol'
|
studies
|
int
|
the studies of every parameter vector with a variability
between the studies ( |
16
|
Returns:
| Type | Description |
|---|---|
PredictiveCheck
|
The bands and the coverage of the data points. |
Raises:
| Type | Description |
|---|---|
ValueError
|
for no parameter vector, quantiles which are not in
|