Understand the idea
Ordinary regression forces every predictor's effect to be a single straight line: one slope, applied everywhere. But plenty of real relationships bend: a drug's effect might rise steeply then plateau; a temperature effect might be U-shaped. A GAM allows each predictor to have its own SMOOTH CURVE shape learned from the data, instead of committing to a straight line upfront.
What makes a GAM special compared to more flexible 'black box' models is that the effects still ADD UP, one predictor at a time. That means you can look at any single predictor's curve in isolation (a 'partial-effect plot') and read exactly what it does to the outcome, holding everything else fixed: you get the flexibility of a bending curve without losing the ability to explain what each piece of the model is doing.
The key number to check for each curve is its 'effective degrees of freedom' (EDF). An EDF near 1 means the curve is basically a straight line after all: no real bend was needed. A bigger EDF means real curvature was found. This is worth repeating because it trips people up: EDF measures COMPLEXITY (how wiggly the curve is), not STRENGTH or SIGNIFICANCE; a gentle, nearly straight curve (EDF near 1) can still be a very strong, highly significant effect, while a wiggly curve (high EDF) is not automatically more important just because it bends more.
A GAM is a form of penalized spline regression: each smooth term is a flexible curve for one predictor, with a penalty that stops it from wiggling more than the data support.
Practitioner explanation
KernelStats builds each smooth term from B-spline basis functions (the spline degrees-of-freedom option sets the basis dimension; the spline degree is usually cubic) and fits by penalized deviance minimization: deviance + lambda * integral of (f''(x))^2 dx, where lambda (the smoothing option) is the roughness-penalty weight; larger lambda produces straighter, smoother curves; smaller lambda allows wigglier curves that chase the data more closely. Gaussian (identity link), binomial (logit), and Poisson (log) response families are supported, mirroring a GLM's family/link choices exactly, and linear_terms can enter alongside smooth_terms for predictors you deliberately want to keep as an ordinary linear effect.
Each smooth term's effective degrees of freedom (EDF) is reported alongside an approximate Wald test (H0: the whole curve is flat / adds nothing); EDF is explicitly the honest 'how complex is this curve' number, not a significance measure, and the total model EDF is what drives the AIC used for model comparison. A small Wald p-value means the predictor matters; the SHAPE of that mattering comes from the partial-effect plot, never from the p-value alone, which the product states directly rather than leaving implicit.
A GAM as fit here has NO automatic interactions: effects are strictly additive on the link scale, so if two predictors' effects genuinely depend on each other, a plain additive GAM will miss that entirely and an explicit tensor-product or bivariate smooth (or an interaction term) is needed to capture it; this is stated as an assumption, not silently assumed away. Tuning the smoothing penalty is a real bias-variance trade-off the analyst controls directly: too LARGE a penalty oversmooths a real bend into a nearly straight line (EDF near 1); too SMALL lets the curve chase noise (EDF pinned near its maximum, the spline degrees of freedom minus 1 after centering). The default smoothing = 1.0 is not scale-free: for a response measured in large units it is a weak penalty, so check the EDF before reading the curve's wiggles.
When to use it
Consider it when
A predictor's relationship with the response is suspected to be curved rather than a straight line, and you still want an interpretable, additive model where each predictor's shape can be read off individually, rather than a black-box alternative.
Use caution when
Two or more predictors are expected to interact (their combined effect is not simply the sum of their separate smooth curves; a plain additive GAM has no automatic way to capture this), the dataset is too small to support the chosen spline basis dimension for a smooth term, or maximum predictive accuracy matters more than interpretability (an ensemble method may outperform a GAM's additive structure).
Formulas and symbols
GAM model
g the link function (identity/Gaussian, logit/binomial, log/Poisson); f_k(X_k) a smooth spline curve; Z_j any predictors entered linearly.
Penalized fitting objective
lambda (the smoothing option) the roughness-penalty weight; larger lambda gives straighter curves.
Effective degrees of freedom
A penalized smooth term costs less than a full integer count of parameters; EDF measures how much wiggle the fit actually used, up to spline_df.
Assumptions and checks
- A GAM adds each predictor's smooth effect on the link scale; it fits no interactions between predictors automatically, so if two predictors act jointly (their effect on the outcome depends on each other), that interaction is missed unless an explicit interaction or tensor-product smooth is added.
In KernelStats: Screened directly: the card refits the same GAM (same bases, same penalty) with centered pairwise product terms added as linear columns (every smooth x smooth pair and every smooth x linear-term pair, up to 30 pairs) and tests the drop in deviance (an F test for the Gaussian family, a chi-squared test otherwise). A significant drop is flagged as a failed 'Additivity (product-interaction screen)' check naming the strongest pair; with a single predictor additivity holds by construction. The screen detects product-shaped interactions only and can miss other interaction shapes; if the refit fails, the card says additivity was NOT checked.
- A smooth term whose effective degrees of freedom sit right at the basis maximum is barely being constrained by the penalty: either the basis is too small to capture the true shape (raise spline_df) or the curve is chasing noise (raise the smoothing penalty); the reported shape cannot be trusted until one of those is checked.
In KernelStats: Checked directly: the card flags the smooth term with the largest EDF when it is within 0.5 of the basis maximum (spline_df - 1), with a note recommending a larger smoothing penalty.
- Linearity. If every smooth term in the model has effective degrees of freedom close to 1 (a straight line), the flexible GAM machinery is being used to fit what is really a linear relationship, and a plain linear regression would report the same fit with simpler, more interpretable coefficients.
In KernelStats: Checked directly: the card flags when every smooth term is effectively linear (EDF approximately 1).
Alternatives
- Linear Regression. Predictor effects are genuinely linear: the smooth terms in a GAM add complexity (and EDF near 1 would confirm this) that a simpler linear model already captures.
- Polynomial Regression. You want to model a specific, known curved shape (a quadratic or cubic trend) with a small number of explicit polynomial terms rather than a flexible, data-driven spline.
- LOESS (Local Regression Smoothing). You want a single smooth curve for one or two predictors without the additive multi-predictor GAM framework, purely for visualization or local smoothing.
Worked example
Scenario
Modeling penguin body mass as a smooth function of flipper length (Gaussian family, default spline settings).
Result
With the default settings (spline_df = 6, smoothing = 1.0) the flipper-length smooth uses EDF = 4.99 of a possible 5 and the card flags it as near the basis maximum; the Wald test gives p < .001 and pseudo-R-squared = 0.78, against R-squared = 0.76 for a straight-line fit.
Interpretation
Flipper length clearly matters, but the curve is using almost all the flexibility it was given for a two-point gain in R-squared over a straight line, so its bends may be noise. The honest next step is to raise the smoothing penalty and compare AIC: if the EDF falls toward 1 with little loss of fit, the simpler linear regression is the better description.
Dataset: penguins.csv
Common misconceptions
Misconception
A GAM gives you a single slope for each predictor, the way ordinary regression does.
Correction
A smooth term has NO single slope: its effect is a curve, and the way to interpret it is to read the shape of that curve in its partial-effect plot, not to look for one coefficient. Only the predictors entered as explicit LINEAR terms have an ordinary single-coefficient slope.
Misconception
A wigglier (higher effective-degrees-of-freedom) curve represents a stronger or more statistically significant effect.
Correction
Effective degrees of freedom measures the curve's COMPLEXITY (how much it bends), not its strength or significance. A gentle, nearly straight curve (EDF close to 1) can be highly significant and explain a great deal of the outcome; a jittery, high-EDF curve can be statistically non-significant. Read the Wald test for significance and the partial-effect plot for shape: EDF answers neither of those questions by itself.
References
- Generalized Additive Models, Hastie, T. J. and Tibshirani, R. J. (1990).
- Generalized Additive Models: An Introduction with R, Wood, S. N. (2017).
