[R] Prediction using GAM

Kerry Bush kerryrekky at yahoo.com
Thu Mar 24 05:31:23 CET 2005


Recently I was using GAM and couldn't help noticing
the following incoherence in prediction:

> data(gam.data)
> data(gam.newdata)
> gam.object <- gam(y ~ s(x,6) + z, data=gam.data)
> predict(gam.object)[1]
        1 
0.8017407 
>
predict(gam.object,data.frame(x=gam.data$x[1],z=gam.data$z[1]))
        1 
0.1668452 

I would expect that using two types of predict
arguments should give me the same results.
When I used this to predict a new data set then it
seems OK:

>
predict(gam.object,data.frame(x=gam.newdata$x[1],z=gam.newdata$z[1]))
        1 
0.4832136 
> predict(gam.object,gam.newdata)[1]
        1 
0.4832136 

Could anybody explain the strange behavior of
predict.gam function?

Thanks,
Kai




More information about the R-help mailing list