3
$\begingroup$

When specifying it's formula GAM has s function for smoothing. Let's say I want to fit mtcars. I can do the following:

Approach 1:

mgcv::gam(mpg ~  cyl + disp + hp + drat + wt + 
  qsec + vs + am + gear + carb, data = mtcars)

Approach 2:

mgcv::gam(mpg ~  s(disp) + s(cyl, k = 2) +  
    s(hp) + drat + wt + qsec + vs + am + gear + 
    carb, data = mtcars)

My question is two fold:

  1. Is approach 1 good enough? How do we know?
  2. In approach 2 how can we choose which variable to smooth? Whether they're disp, wt or other? In the above example I just arbitrarily choose disp, cyl and hp for smoothing.
$\endgroup$
2
  • 2
    $\begingroup$ Note that Approach 1 is the same as a standard lm() fit. Unless you specify a smooth, gam() treats the predictor as a linear contribution to outcome. If there are no smooths then all predictors are treated as in lm(). $\endgroup$
    – EdM
    Jul 6, 2022 at 14:58
  • $\begingroup$ @EdM Thanks. Noted. But for approach 2, how can one decide which variables to smooth? $\endgroup$ Jul 6, 2022 at 23:19

1 Answer 1

4
$\begingroup$

Flexible modeling of continuous predictors is a highly favored approach. You seldom can count on a strictly linear association of such predictors with outcome, which is what's implied when you omit a smooth from a generalized additive model (GAM) or build a linear regression model without higher-order predictor terms like splines.

Frank Harrell discusses this in his course notes and book; in particular, see Chapter 4 for a detailed outline of general regression modeling strategy and Chapter 2 for discussion of spline modeling. If you have enough data to do so without overfitting, the default should be to smooth all continuous predictors and multi-level ordered categorical predictors in some way.

A GAM provides a convenient way to do that, as the penalization inherent in many types of smooths tends to minimize overfitting. A GAM does not prevent overfitting, however, particularly when the model includes unpenalized parametric terms like categorical predictors (vs, am in mtcars)or un-smoothed continuous predictors (drat, wt, qsec in your Approach 2).

A danger is that the apparent simplicity of specifying a GAM can tempt you to avoid applying your knowledge of the subject matter. Harrell emphasizes making deliberate choices about how many degrees of freedom (df) to devote to each predictor, perhaps using more df for a predictor of primary interest and fewer for those included because they need to be controlled for.

With standard regression splines (available but not a default in mgcv::gam()) you implement that choice by the number of knots. If you simply use default thin-plate regression splines via s() in a GAM, however, you are letting the software make that choice for you. There's also a risk that the primary GAM focus on smooth modeling of continuous predictors might inhibit you from including important interaction terms involving those predictors. You can model such interactions, but it's more complicated than just wrapping s() around each continuous predictor individually.

So, as in many aspects of statistical practice, the primary consideration in choosing what to smooth, how to smooth, and how much to smooth in a GAM comes down to intelligent application of subject-matter knowledge.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.