Skip to content
Prev 274417 / 398506 Next

Question about GAMs

predict.gam is returning a matrix with a named column for each term. 
Select the appropriate column. Example below

library(mgcv)
n<-200;sig <- 2
dat <- gamSim(1,n=n,scale=sig)
b <- gam(y~s(x0)+s(I(x1^2))+s(x2)+offset(x3),data=dat)
newd <- data.frame(x0=(0:30)/30,x1=(0:30)/30,x2=(0:30)/30,x3=(0:30)/30)
pred <- predict.gam(b,newd,type="terms")

pred[,3] ## extracts s(x2)
pred[,"s(x2)"] ## same
On 14/10/11 04:54, pigpigmeow wrote: