# How to know when a generalized additive model need to be used for binary data?

When we have response variable that is of binary type and our interest is to know how probability is associated with covariates then we use logistic regression.

But I specifically want to know about logistic generalized additive models (gam).

Suppose, I have a data with binary response. How can I know whether here I need a linear or a gam logistic?

As for other data type, I can plot scatter plot of response vs covariate and if I see nonlinear pattern I can use gam. But for binary response, I can not have that choice.

(Adding mgcv tag as anyone using it may have understanding on this issue).

• Does this answer your question? When to use a GAM vs GLM Apr 6, 2023 at 11:26
• (In short: We never do know beforehand if there is non-linearity in how a predictor affects our outcome. That is true for all modelling endeavours unless we have intricate knowledge about the system's dynamics.) Apr 6, 2023 at 11:30
• @TanIa What about that does not answer your question? At a glance, it sure looks like a duplicate. Is the question not the same as yours (and, if so, why)? Is the question the same but the answer inadequate?
– Dave
Apr 6, 2023 at 12:10
• @Dave One could interpret the question as asking "how can I test statistically if I need a smooth over a linear function?", which is what I answer below (and which isn't addressed at the other Q&A). But I only interpreted the question that way because I get asked this question a lot when teaching GAM - it's not at all clear from the Q if this is what is being asked; "how can I know..." isn't very precise/clear. Apr 6, 2023 at 12:43

A logistic GLM will fit linear functions of covariates on the scale of the link function (linear predictor), whereas a GAM would fit smooth functions on this scale. If you aren't sure if you need a GAM, you could just fit the GAM, check if the size of the basis expansion for each smooth was sufficiently large (via k.check() or gam.check()), and rely on the smoothing parameters to shrink away unnecessary wiggliness.
# pseudo code

where we fit a linear term in x plus a smooth function of x, but we have modified the basis for the smooth so that it no longer includes linear functions in the span of the basis. This modification is done by m = c(2, 0), which indicates we want the usual second order derivative penalty but with a 0 size null space (the span of functions that aren't affected by the penalty because they have 0 second derivative). With this specification, the output from summary() will give a test for the necessity of the wiggliness provided by the smooth over the linear effect estimated by the linear term.
• The assumptions of the two methods are very different; it makes no sense to assume that the estimated function(s) are smooth and that the functions are piecewise constant. What does "observed linear predictor" mean? The linear predictor is not observed, it is a linear combination of terms, the constants therefor having been estimated from the observed data. If you mean't can we predict from the model for the observed data on the scale of the linear predictor, then yes predict(m, type = "link"), which is the default. Apr 6, 2023 at 13:27