[R] GAMM : how to use a smoother for some levels of a variable, and a linear effect for other levels?
JANSEN, Ivy
Ivy.JANSEN at INBO.BE
Wed Apr 14 10:03:50 CEST 2010
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.
More information about the R-help
mailing list