I am learning about Generalized Additive Models (GAMS) and have found in multiple locations a claim that a GAM with one independent variable is identical to a bivariate LOESS regression. Is this claim correct?
I have been unable to obtain the same answer using the loess
function in base R
and the gam
function in the R
package mgcv
. Here is a link to a similar question from 2009 on a different forum: http://r.789695.n4.nabble.com/Difference-between-gam-and-loess-td881045.html
Below is my R
code, which I modified from code provided at the link above. The gam
function in R
has numerous options. If a GAM with one independent variable is identical to a bivariate LOESS regression could someone provide the option settings needed? I have tried a wide range of values for span
in the loess
function and am only showing a few.
Thank you for any advice or assistance.
library(mgcv)
set.seed(1234)
# generate data
x <- sort(runif(100))
y <- sin(2*pi*x) + rnorm(10, sd=0.1)
mgcv.1 <- gam(y ~ s(x), family=gaussian(), weights=NULL, subset=NULL,
offset=NULL, method = "GCV.Cp",
optimizer=c("outer", "newton"), control=list(), scale=0,
select=FALSE, knots=NULL, sp=NULL, min.sp=NULL, H=NULL, gamma=1,
fit=TRUE, paraPen=NULL, G=NULL, drop.unused.levels=TRUE,
bs="cr")
base.r <- loess(y ~ x, degree=1, span=0.50) ; summary(base.r$fitted - mgcv.1$fitted)
base.r <- loess(y ~ x, degree=1, span=0.75) ; summary(base.r$fitted - mgcv.1$fitted)
base.r <- loess(y ~ x, degree=2, span=0.50) ; summary(base.r$fitted - mgcv.1$fitted)
base.r <- loess(y ~ x, degree=2, span=0.75) ; summary(base.r$fitted - mgcv.1$fitted)
EDIT
According to lecture notes at the link here:
http://polisci.msu.edu/jacoby/icpsr/regress3/lectures/week4/16.GAM.pdf
the gam
function in mgcv
only fits smoothing splines, but local polynomial regression could be done in S-PLUS
. Perhaps that is why I cannot obtain the same answer with mgcv
as I get with the loess
function? Perhaps another GAM package in R
does allow local polynomial regression?
Best Answer
Not really a full answer, but too long for a comment:
s
sets up a spline, whereasloess
does a local regression.In the
gam
package (maybemgcv
too, not too familiar with that one) you can also feed a local regression, as inThat does not produce the same fitted values either, but maybe you can further play around with the settings of
lo
andloess
.