################################################### ### chunk number 1: ################################################### options(show.signif.stars=FALSE,digits=4,width=80) ################################################### ### chunk number 2: one ################################################### library(alr3) library(mgcv) data(trees) pairs(trees) ################################################### ### chunk number 3: two ################################################### m0 <- lm(Volume~Height+Girth,trees) mmp(m0) ################################################### ### chunk number 4: three ################################################### summary(m1 <- gam(Volume~s(Height) + s(Girth), data=trees)) ################################################### ### chunk number 5: threea ################################################### summary(m1a <- gam(Volume ~ s(Height, bs="cr") + s(Girth, bs="cr"), data=trees)) ################################################### ### chunk number 6: three ################################################### par(mfrow=c(1,3)) plot(m1, residuals=TRUE, select=1) plot(m1, residuals=TRUE, select=2) mmp(m1) # from the alr3 package ################################################### ### chunk number 7: ################################################### m2 <-update(m1, ~ . - s(Girth)) anova(m2, m1, test="F") ################################################### ### chunk number 8: ################################################### summary(m3 <- update(m1, ~ . - s(Height) + Height)) AIC(m2, m3, m1) ################################################### ### chunk number 9: five ################################################### par(mfrow=c(1, 2)) summary(m4 <- update(m1, ~ s(Height, Girth, k=8))) AIC(m1, m4) plot(m4) plot(predict(m1), predict(m4), xlab="Predictions, additive", ylab="Predictions, nonadditive") abline(0, 1)