[R-sig-ME] Longitudinal Model
Leonardo Bergamini
llbergamini at gmail.com
Wed Nov 19 13:44:03 CET 2014
Hi fellows,
I would like some help at adjusting a mixed model as follows:
I have collected data on the abundance of caterpillars (NC) on trees at
three sites over 48 monthly samplings. I am interested in understanding how
the three environmental variables I have for the region (namely mean
temperature (Temp) in that month, total precipitation (R) and mean relative
humidity (H)) correlate with the number of caterpillars, and whether this
relationship is different at the three sites.
So far I've been thinking about a lme model, in order to include the
temporal autocorrelation structure, but I'm not sure how to specify the
random effects and the error structure. I also would like to test at which
temporal lag (same month, last month or two months earlier) the
relationship is stronger.
Example:
## simulating the data
set.seed(1)
df<-data.frame(
Temp=rep(26+sin(seq(0,2*pi,(2*pi+1)/13))+rnorm(48,0,0.3),3),
P=rep(500+100*(1-sin(seq(0,2*pi,(2*pi+1)/13)))+rnorm(48,100,30),3),
H=rep(((2+(1-sin(seq(0,2*pi,(2*pi+1)/13))))/4)+rnorm(48,0,0.05),3),
site=rep(c("A","B","C"),each=48),
NC=round(4*(1-sin(seq(0,2*pi,(2*pi+1)/13)))+rnorm(144,10,4)),
month=rep(1:48,3)
)
## model
library(nlme)
model1<-lme(NC~Temp+P+H,
random=~1|site,correlation=corAR1(form=~month|site),data=df)
Any help on this specific problem or pointings towards introductory
literature would be great
Thanks,
Leonardo
[[alternative HTML version deleted]]
More information about the R-sig-mixed-models
mailing list