Ken Knoblauch <ken.knoblauch <at> inserm.fr> writes: > 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). > > 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 Let me correct this before someone else does for me, (It's getting late on Friday afternoon!) The interaction in the model matrix would not be with day. In my case, I had a covariate for the by variable and a factor with two levels, so I used the interaction to separate them with respect to the smooths. I think that you might be able to get the columns from the model matrix columns from the mapID term by itself. Sorry for the misstep.
Ken ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.