fit.compare¶
Comparison of models by the corrected Akaike information criterion.
compare_models fits every model to the same data and ranks them per sample
by AICc (Burnham & Anderson 2002, ch. 2): Delta_i = AICc_i - min_j AICc_j
and the Akaike weight w_i = exp(-Delta_i / 2) / sum_j exp(-Delta_j / 2), the
probability that model i is the best of the set given the candidates
considered. AICc counts the residual variance as an estimated parameter,
K = k + 1 (Burnham & Anderson 2002, sec. 2.2, 6.9.6); a model whose AICc is
NaN (too few points for its number of parameters, n - K - 1 <= 0) gets
weight 0 and is never picked as best; when every model of a sample is
NaN, best is the empty string.
ModelComparison
dataclass
¶
The fits of several models and their ranking by AICc.
Attributes:
| Name | Type | Description |
|---|---|---|
results |
dict[str, FitResult]
|
model name to its |
table |
DataFrame
|
one row per sample and model, with the sample dims, |
best |
DataArray
|
name of the best model per sample, over the sample dimensions (empty string for a sample where no model fitted). |
compare_models
¶
compare_models(
models,
x,
y=None,
*,
sd=None,
options=None,
x_unit=None,
y_unit=None,
dims=None,
coords=None,
)
Fit every model to the same data and rank them per sample by AICc.
Delta_i = AICc_i - min_j AICc_j and the Akaike weight
w_i = exp(-Delta_i / 2) / sum_j exp(-Delta_j / 2) (Burnham & Anderson
2002, ch. 2) are computed independently for every sample, so a different
model can be the best fit of different samples of a batch.
A Timecourse or a Timecourses batch is given as x alone: every
model is then fitted with fit_timecourse or fit_timecourses, which
take the times relative to the first dose and the units from the data, so
that choosing between MonoExp, BiExp and Bateman for a curve or a
batch needs no flattening and no unit by hand. sd, x_unit, y_unit,
dims and coords come from the data then and must not be given.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
models
|
Sequence[Model]
|
the candidate models, with distinct |
required |
x
|
Any
|
independent variable as for |
required |
y
|
Any
|
dependent variable, as for |
None
|
Other Parameters:
| Name | Type | Description |
|---|---|---|
sd |
Any | None
|
standard deviations, as for |
options |
FitOptions | None
|
fit options shared by every model. |
x_unit |
str | None
|
unit of |
y_unit |
str | None
|
unit of |
dims |
Sequence[str] | None
|
sample dimension names for a 2-D |
coords |
dict[str, Any] | None
|
coordinates of the sample dimensions. |
Returns:
| Type | Description |
|---|---|
ModelComparison
|
The comparison. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if two models share a |