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")
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)
medv
with a local regression for the lstat
term, with a span of 0.5.
Also add a degree-3 smoothing spline function of rm
. Store the result in the variable gam1
.medv
on the training set. Store the results in the variable preds
.Assume that:
(ignore: test Dodona)