[R] Help with lmer, nested data and repeated measures

Simon Garnier sgarnier at princeton.edu
Thu Nov 18 18:58:10 CET 2010


Dear all,

I'm discovering the somehow confusing (for me) world of linear mixed models after having been advised it could be the best option to analyze my dataset. After several days of reading, I'm not sure that what I ended up with makes some sense and I'd greatly appreciate any help and explanations.

The dataset has been obtained as follows. In 15 different locations, I counted during 10 seconds the number of ants crossing a gap, before and after destroying a bridge that ants had previously built over the gap. I then waited for the ants to rebuild the bridge and repeated two more times the counting and destroying process. Therefore, for each gap observed, I have 3 replicates of the same experiment, each of them providing 1 count value for each treatment tested (before and after bridge destruction), i.e. 6 values in total per gap. I also measured for each gap its length. 

I now want to model the effect of the gap length (GapLength, continuous variable), the treatment (Treatment, categorical variable) and the replicate position (Replicate, categorical variable) on the number of ants crossing the gap (AntCount, count variable). As far as I understand, the gap (Gap) can be treated here as a random effect, the gap length, the treatment and the replicate position as fixed effects. Moreover, the treatment variable is nested in the replicate position variable that is also nested in the gap variable. Finally, since I have count data, a poisson distribution should be used for the model. With all this information in mind and some additional information from various sources, I ended up with the following R code:

lmer(AntCount ~ Treatment + GapLength + (Treatment | Gap / Replicate) + (GapLength | Gap), data=dat, family=poisson(link=log))

The code runs fine and does not return any error. But of course this does not mean the model was correctly designed. Am I right when I'm doing this or am I (most likely) completely wrong? 

Thanks in advance for your help.

Best,
Simon. 

-- 
--------------------------------------------------------------------------------
Dr. Simon Garnier
Department of Ecology & Evolutionary Biology
Princeton University
Guyot Hall

e-mail: sgarnier at princeton.edu / simon.garnier at gmail.com
website: http://www.simongarnier.com
photoblog: http://www.simongarnier.org
--------------------------------------------------------------------------------



More information about the R-help mailing list