compare_distributions()

Fit multiple parametric distributions and return an AIC/BIC comparison table.

Usage

Source

compare_distributions(
    surv,
    *,
    dists=None,
    format=None,
)

This is the primary model-selection helper for univariate parametric survival analysis. It fits each distribution by maximum likelihood, then ranks them by AIC (lower is better). Use this early in an analysis to decide which distributional family best describes your data before moving on to regression modelling with AFT.

Parameters

surv: Any

A right-censored Surv response.

dists: list[str] | None = None

Distribution families to compare. The default is all four: ["weibull", "exponential", "lognormal", "loglogistic"].

format: str | None = None
Output format: None (auto-detect), "pandas", "polars", or "pyarrow".

Returns

DataFrame
One row per distribution, sorted by AIC, with columns dist, n_params, loglik, aic, and bic.

Details

AIC (Akaike Information Criterion) and BIC (Bayesian Information Criterion) both penalise model complexity but differ in how strongly. AIC penalises by 2k (where k is the number of parameters), while BIC penalises by k \log n, giving a stronger preference for simpler models when the sample size is large. The table is sorted by AIC, but when AIC and BIC disagree the more parsimonious model (favoured by BIC) is often the safer choice.

Examples

Compare all four distribution families on the lung cancer dataset and see which one fits best:

import greenwood as gw

# Load data and build a right-censored response
lung = gw.load_dataset("lung", backend="polars")
y = gw.Surv.right(lung["time"], event=(lung["status"] == 2))

# Compare all four distributions by AIC
gw.compare_distributions(y, format="polars")
shape: (4, 5)
distn_paramsloglikaicbic
stri64f64f64f64
"weibull"2-1153.8511882311.7023762318.561067
"loglogistic"2-1160.9306242325.8612472332.719938
"exponential"1-1162.3381762326.6763522330.105697
"lognormal"2-1169.2690552342.5381112349.396802