GAMM : how to use a smoother for some levels of a variable, and a linear effect for other levels?
Both versions of this should have worked, but you are right that the first version didn't when used with `gamm', I've fixed this for mgcv 1.6-2 (`mgcv:gam' was ok). Thanks for this. best, Simon
On Wednesday 14 April 2010 09:03, JANSEN, Ivy wrote:
Hi,
I was reading the book on "Mixed Effects Models and Extensions in
Ecology with R" by Zuur et al.
In Section 6.2, an example is discussed where a gamm-model is fitted,
with a smoother for time, which differs for each value of ID (4
different bird species). In earlier versions of R, the following code
was used
BM2<-gamm(Birds~Rain+ID+
s(Time,by=as.numeric(ID=="Stilt.Oahu"))+
s(Time,by=as.numeric(ID=="Stilt.Maui"))+
s(Time,by=as.numeric(ID=="Coot.Oahu"))+
s(Time,by=as.numeric(ID=="Coot.Maui")),
correlation=corAR1(form=~Time |ID ),
weights=varIdent(form=~1|ID))
However, in the current version of R, this does not work anymore, and
should be changed into
BM2<-gamm(Birds~Rain+ID+
s(Time,by=ID),
correlation=corAR1(form=~Time |ID ),
weights=varIdent(form=~1|ID))
It turns out that 2 of the 4 smoothers have estimated degrees of freedom
of 1, so a linear effect would be sufficient.
Now my question is how I need to change the code in order to have a time
smoother for ID=Coot.Oahu and ID=Coot.Maui, and a linear time effect for
ID=Stilt.Oahu and ID=Stilt.Maui. With the "old" R-code, this seems
trivial, but I don't have any idea how to do it in the newest R-version
(interactions with a dummy variable do not work in gamm).
Thanks,
Ivy
Druk dit bericht a.u.b. niet onnodig af.
Please do not print this message unnecessarily.
Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver
weer en binden het INBO onder geen enkel beding, zolang dit bericht niet
bevestigd is door een geldig ondertekend document. The views expressed in
this message and any annex are purely those of the writer and may not be
regarded as stating an official position of INBO, as long as the message is
not confirmed by a duly signed document.
______________________________________________ R-help at 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.
> Simon Wood, Mathematical Sciences, University of Bath, Bath, BA2 7AY UK > +44 1225 386603 www.maths.bath.ac.uk/~sw283