geom_smooth using splines

Hello everyone,

Any insights into the differences of splines used in each algorithm would be really helpful.
I’m particularly interested in whether these algorithms use cubic splines, natural splines, or smoothing splines, and how each type influences the line's shape, flexibility, and fit quality in the model.
Understanding the advantages or limitations each spline type brings to the algorithm would also be really helpful.

ggplot(df, aes(x=x, y=y)) +
geom_smooth(method = 'glm',
method.args = list(family = "binomial"),
formula = y ~ splines::ns(x, 3)) #I guess this uses natural splines as indicated by the ::ns

ggplot(df, aes(x=x, y=y)) +
geom_smooth(method = 'gam',
method.args = list(family = "binomial"),
formula = y ~ s(x, bs = "cs")) #cubic spline with shrinkage component?

ggplot(df, aes(x=x, y=y)) +
geom_smooth(method = 'gam',
method.args = list(family = "binomial"),
formula = y ~ s(x, bs = "cr")) #cubic regression spline?

while the geom_smooth docs says that "Calculation is performed by the (currently undocumented) predictdf()", you can look up ?predict.loess for example.

As geom_smooth does not return the model (its main goal is to plot some smoothed version), if you're interested in the quality and interpretation of the fit, you probably want to run each model yourself and look at the relevant "quality control" (e.g. distribution of residuals). That also gives you metrics like AIC to compare models.

As far as I can tell, using ns() in a glm is a "quick-and-dirty" way to get halfway to a GAM, if you're actually interested in the fit you probably want to use mgcv::gam() yourself (I like this course about GAMs).

In particular, you'll find that ?mgcv::smooth.terms describes different splines available in mgcv with some explanations. EDIT: there is also a useful discussion of the different types of splines here.