Learn Before
Relation
R implementation of GAMs
Example with wage data:
Since this is simply a linear regression model with several basis functions, we simply use the lm() function.
gam1 <- lm(wage ~ ns(age, 5) + education, data=Wage)
To fit more complex splines, or other components that cannot be specified as basis functions, we need to use the gam library in R. the s() function is used to indicate a smoothing spline.
library(gam) ## Loaded gam 1.09.1 gam2 <- gam(wage~s(year, 4) + s(age, 5) + education, data=Wage)
0
4
Updated 2020-02-25
Tags
Data Science