We can also use local regression fits as building blocks in a GAM, using the lo() function.

gam.lo <- gam(wage ~ s(year, df = 4) + lo(age, span = 0.7) + education, data = Wage)
plot.Gam(gam.lo, se = TRUE, col = "green")

plot

Here we have used local regression for the age term, with a span of 0.7. We can also use the lo() function to create interactions before calling the gam() function. For example,

gam.lo.i <- gam(wage ~ lo(year, age, span = 0.5) + education, data = Wage)

fits a two-term model, in which the first term is an interaction between year and age, fit by a local regression surface.

We can make predictions from gam objects, just like from lm objects, using the predict() method for the class gam. Here we make predictions on the training set.

preds <- predict(gam.m2, newdata = Wage)

Questions

Assume that:

(ignore: test Dodona)