A GAM extends the generalized linear model by replacing some or all linear predictor terms with smooth, data-driven functions of the covariates:
g(\mathbb{E}[y_i]) = \eta_i = \beta_0 + \sum_j \beta_j x_{ij} + \sum_k f_k(z_{ik})
where g is a link function, \beta_j x_{ij} are ordinary parametric (linear) terms, and each f_k is an unspecified smooth function represented by a spline basis (s()) or a tensor product of bases for multivariate smooths (te(), ti(), t2()). This lets the model capture nonlinear relationships without having to guess a parametric form ahead of time, while still supporting the full range of exponential-family response distributions (Gaussian, Binomial, Poisson, Gamma, Tweedie, and more) via a Family object.
Use GAM when you suspect a covariate’s effect on the response is nonlinear, when you want interaction surfaces between two or more continuous covariates, or when you want automatic, data-driven control of model complexity rather than manually choosing a polynomial degree or a fixed set of basis functions.
A GAM is specified with a formula string in an R/mgcv-like syntax, e.g. "y ~ s(x1) + s(x2, bs='cr', k=15) + te(x3, x4) + group", where s() denotes a univariate (or by=-varying) smooth, te()/ti()/t2() denote tensor-product smooths of two or more variables, and bare names denote ordinary parametric terms. See Formula, SmoothTerm, LinearTerm, InteractionTerm, and OffsetTerm for the term types this formula parses into.
Fitting (fit()) proceeds by Penalized Iteratively Reweighted Least Squares (P-IRLS): each smooth’s wiggliness is controlled by a quadratic penalty \lambda_k \boldsymbol{\beta}_k^T
\mathbf{S}_k \boldsymbol{\beta}_k on its coefficients, and the smoothing parameters \lambda_k are themselves estimated from the data. By default this is via Generalized Cross-Validation (GCV), or via Restricted Maximum Likelihood (REML) or Marginal Likelihood (ML) when smooths are treated as correlated random effects. Larger \lambda_k shrinks a smooth toward a simpler (e.g. linear or constant) shape; smaller \lambda_k allows more flexibility. This automatic selection is what distinguishes a GAM from simply choosing a fixed spline basis: the effective complexity of each term (its effective degrees of freedom, or EDF) is learned rather than fixed in advance.
Once fitted, a GAM supports prediction with standard errors and intervals (predict()), partial-effect plotting (plot()), residual and basis-dimension diagnostics (check(), gam_check(), k_check()), hypothesis tests for parametric and smooth terms (parametric_tests(), smooth_tests()), and a text summary (summary()) analogous to summary.gam() in R’s mgcv.