[R] Predictions with GAM

Ken Knoblauch ken.knoblauch at inserm.fr
Fri Jan 16 15:51:54 CET 2009


Hi,

Robbert Langenberg <mcrelay <at> gmail.com> writes:
> I am trying to get a prediction of my GAM on a response type. So that I
> eventually get plots with the correct values on my ylab.
> The problem I am encountering now is that I cannot seem to get it done for
> the following type of model:
> 
> *model3<-gam(y_no~s(day,by=mapID),family=binomial, data=mergeday)*
> 
> My mapID consists of 8 levels of which I get individual plots with *
> plot(model3)*. When I do predict with a newdata in it just like my first
> model I need all columns to have the same amount of rows or else R will not
> except it ofcourse, the col.names need to at least include day and mapID.
> This way I can not get a prediction working for this GAM, I am confused
> because of this part in the model: *s(day,by=mapID).
> 
> I hope someone can help me out with this,
> 
> Sincerely yours,
> 
> Robbert Langenberg
I'm not sure that this will work for you, but I had a similar
situation and was able to get predict to work (after helpful
advice from Simon Wood) with a by variable by generating 
a model matrix for a model with the interaction of the covariate 
and the by term, something like

model.matrix(~ day:mapID - 1, data = mergeday)

in your case.
I added the appropriate columns into my data frame and 
also to the newdata for predict.  You can see an example 
in the appendix of

http://www.journalofvision.org/8/16/10/

HTH,

Ken

-- 
Ken Knoblauch
Inserm U846
Institut Cellule Souche et Cerveau
Département Neurosciences Intégratives
18 avenue du Doyen Lépine
69500 Bron
France
tel: +33 (0)4 72 91 34 77
fax: +33 (0)4 72 91 34 61
portable: +33 (0)6 84 10 64 10
http://www.sbri.fr




More information about the R-help mailing list