Learn Before
Code

Fitting generalized additive models in R

For the Wage data, an additive model expressed with explicit spline basis functions can be fitted using lm():

gam1 <- lm(wage ~ ns(age, 5) + education, data = Wage)

To specify smooth terms with s(), use gam() from the gam library:

library(gam) gam2 <- gam(wage ~ s(year, 4) + s(age, 5) + education, data = Wage)

0

4

Updated 2026-09-19

Tags

Data Science