Skip to content

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

ModelComparison(results, table, best)

The fits of several models and their ranking by AICc.

Attributes:

Name Type Description
results dict[str, FitResult]

model name to its FitResult.

table DataFrame

one row per sample and model, with the sample dims, model, n_parameters, aicc, delta_aicc, akaike_weight and best.

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 names.

required
x Any

independent variable as for fit, or a Timecourse or a Timecourses batch carrying both variables.

required
y Any

dependent variable, as for fit; left out for a curve or a batch.

None

Other Parameters:

Name Type Description
sd Any | None

standard deviations, as for fit.

options FitOptions | None

fit options shared by every model.

x_unit str | None

unit of x, "dimensionless" when it is not given.

y_unit str | None

unit of y, "dimensionless" when it is not given.

dims Sequence[str] | None

sample dimension names for a 2-D y.

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 name, if y is missing for data which is not a curve or a batch, or if an argument of the array form is given with a curve or a batch.