Skip to content
Prev 207445 / 398506 Next

How to define degree=1 in mgcv

On Sun, 2010-01-24 at 16:28 -0500, hellen lee wrote:
require(mgcv)
require(splines)
data(airquality)

m1 <- glm(Ozone ~ Wind, data = airquality)
m2 <- gam(Ozone ~ Wind, data = airquality)
m3 <- glm(Ozone ~ ns(Wind, df = 1), data = airquality)

For gam, I don't think you can set a smooth to be linear, which is what
I interpret degree = 1 to be (I also don't know where you get degree = 1
from, this isn't anything to do with ns() in package splines). So we
just don't specify that Wind be a smoother in the GAM --- not sure if
that is what you wanted?

Compare the fits using say summary:

e.g. summary(m1); summary(m2)

Also, from the above, note that these are all linear models (as opposed
to generalised) and would be fitted more efficiently using lm():

m4 <- lm(Ozone ~ Wind, data = airquality)
m5 <- lm(Ozone ~ ns(Wind, df = 1), data = airquality)
[1] TRUE
[1] TRUE
[1] TRUE
[1] TRUE

HTH

G