[R] Prediction interval with GAM?

Zofia Ecaterina Taranu zofia.taranu at gmail.com
Tue Jun 3 16:52:23 CEST 2014

I apologize in advance for my very basic question. I would like to plot prediction intervals for my GAM model, however, instead of using a Gamma GAM, I assumed a Gaussian distribution (I standardized my response variable, which resulted in negative values).

To create the prediction interval for my model, I simply changed the code below:

yr <- matrix(rgamma(fv*0,shape=1/b$scale,scale=fv*scale),nrow(fv),ncol(fv))


yr <- matrix(rnorm(fv*0,mean=mean(data$Y),sd=sd(data$Y)),nrow(fv),ncol(fv)) # where Y is my response variable

However, the prediction interval created does not capture the trend in my data (see attached figure). I imagine I also should have changed:

fv <- exp(lp)


Xp <- predict(b,newdata=data.frame(x=xp),type="lpmatrix")
lp <- Xp%*%br

Any suggestions would be greatly appreciated!

Best regards,


Stagiaire Postdoctoral Université de Montréal
Département de sciences biologiques
Pavillon Marie-Victorin
90, av. Vincent-d'Indy
Outremont, QC H2V 2S9

More information about the R-help mailing list