Compare multiple fitted GAMs in a summary table.
Collects AIC, BIC, deviance explained, adjusted R-squared, EDF, GCV (when available), and scale from each model, sorts by AIC, and computes delta-AIC from the best model.
Parameters
*models: GAM
-
Two or more fitted GAM objects.
Returns
ComparisonResult
-
Comparison table sorted by AIC (best first).
Raises
ValueError
-
If fewer than 2 models are provided.
Examples
import numpy as np
import whittaker as wk
rng = np.random.default_rng(0)
x = np.linspace(0, 2 * np.pi, 200)
y = np.sin(x) + rng.normal(0, 0.3, 200)
data = {"x": x, "y": y}
m1 = wk.GAM("y ~ x").fit(data)
m2 = wk.GAM("y ~ s(x, k=5)").fit(data)
m3 = wk.GAM("y ~ s(x, k=15)").fit(data)
print(wk.compare(m1, m2, m3))
Model Comparison (3 models, 200 observations)
# Formula AIC ΔAIC BIC Dev.Expl. Adj.R² EDF GCV
--- ------------------------------ ---------- -------- ---------- ---------- -------- ------- ----------
1 y ~ s(x, k=5) 78.32 +0.00 94.67 86.7% 0.8636 5.0 0.086642
2 y ~ s(x, k=15) 79.21 +0.89 103.14 87.0% 0.8646 7.3 0.087059
3 y ~ x 332.62 +254.30 339.22 51.1% 0.5065 2.0 0.308909