I don't understand why the below two gam models produce different results. The only difference is in one of the models I added the namespace specifier gam::
before the functions gam
and s
.
I want to do this because I am exploring the differences between running the gam function in the gam package and in the mgcv package.
library(ISLR)
library(gam)
gam.m3 <- gam::gam(wage ~ gam::s(year,4) + gam::s(age,5) + education,data=Wage)
gam.m3.orig <- gam(wage ~ s(year,4) + s(age,5) + education, data=Wage)
#Coefficients are different
coef(gam.m3)[1]; coef(gam.m3.orig)[1]
#Models are different
gam.m3$df.residual; gam.m3.orig$df.residual
Here is the output. It seems like the coefficients and degrees of freedom should not be different; in fact the two models should be exactly the same. But, they are different and I don't understand why. Any suggestions welcome, I'm kind of at a loss right now.
> library(ISLR)
> library(gam)
Loading required package: splines
Loading required package: foreach
Loaded gam 1.16
> gam.m3 <- gam::gam(wage ~ gam::s(year,4) + gam::s(age,5) + education, data=Wage)
Warning message:
In model.matrix.default(mt, mf, contrasts) :
non-list contrasts argument ignored
> gam.m3.orig <- gam(wage ~ s(year,4) + s(age,5) + education, data=Wage)
Warning message:
In model.matrix.default(mt, mf, contrasts) :
non-list contrasts argument ignored
>
> #Coefficients are different
> coef(gam.m3)[1]; coef(gam.m3.orig)[1]
(Intercept)
-2058.077
(Intercept)
-2339.364
>
> #Models are different
> gam.m3$df.residual; gam.m3.orig$df.residual
[1] 2993
[1] 2986