Produce GAM diagnostic plots.
check(
model,
plots=None,
)
Provides the standard suite of residual diagnostics used to assess GAM fit quality, analogous to mgcv::gam.check() in R. All requested diagnostics are returned as a single vertically concatenated Altair chart so calling wk.check(model) as the last expression in a cell displays inline. Available plots (selected via plots=):
"qq": QQ plot of deviance residuals against theoretical normal quantiles. Systematic curvature away from the reference line suggests the response distribution (family) may be misspecified.
"residuals": Pearson residuals vs fitted values. A even, patternless scatter around zero is the target; funnel shapes suggest heteroscedasticity (consider a location-scale family), and curvature suggests a missing or under-smoothed term.
"histogram": Histogram of deviance residuals, for checking overall symmetry and shape.
"response": Observed response vs fitted values, with a 1:1 reference line, for an overall sense of fit quality and to spot outliers.
Parameters
model: GAM
-
A fitted GAM.
plots: tuple[str, …] | list[str] | None = None
-
Which diagnostic plots to include. Pass a list of names (e.g.,
["qq", "residuals"]) or None (default) for all four, in the order "qq", "residuals", "histogram", "response".
Returns
altair.VConcatChart
-
All requested diagnostic plots stacked vertically into a single chart.
Examples
import numpy as np
from whittaker.gam import GAM
from whittaker.plotting import check
rng = np.random.default_rng(0)
n = 300
x = rng.uniform(0, 1, n)
y = np.sin(2 * np.pi * x) + rng.normal(scale=0.2, size=n)
model = GAM("y ~ s(x)").fit({"x": x, "y": y})
chart = check(model, plots=["qq", "residuals"])
print(type(chart).__name__)