# Formulating a model statement using lmer for repeated measures in a blocked design in R

I am in the midst of analyzing data that I thought were rather simplistic, but I find myself in need of guidance. The function lmer() has been suggested, but I'm unclear about groups to be included when identifying random effects despite consulting every resource I could get my hands on. I think I know just enough about R to get myself into trouble, so please accept my apologies in advance if this should be obvious!

The design: Three blocks [to which experimental units & treatments were randomly assigned], each containing every combination of 3 species (spp) and 4 treatments (trt). Response (PN) was measured weekly for 10 weeks (Week). I expect the species will differ, so - to simplify - I am running a separate model for each species. Within each of the spp x trt "tubs", I have three units which allowed a mean response (meanPN) and variance (varPN), so I'm using meanPN as my response and will weight the model by 1/varPN.

my model:

meanPN ~ Trt + Block + Time (+ interactions) + error


maybe the statement (excluding interactions for now as I try to wrap my mind around this) would be:

lmer(meanPN ~ Trt + (Trt|Week) + (1|Block) , data=SumExpt, weights=1/varPN)


Can you help me to understand why I would use (1|Week) versus (Trt|Week) - or perhaps, when would each case be appropriate?

Also, does one need to identify Week as the repeated variable, or is R interpreting that based on the pipe character?

Finally, if I understand what I've read correctly, the interactions are handled in the denominators calculating the F-statistic. Is that proper understanding?

-
It's a little hard to understand the structure of your experiment and data. It sounds like both species and treatment were manipulated between experimental units (i.e., each unit is in only one "tub"), is that correct? How are the blocks different from one another? You said each one contains all spp-x-trt combinations, so is it just different units in each block? Are you interested in change over time, or is that just multiple observations? – Dan M. Sep 27 '12 at 16:17
3 of same species in a tub subjected to 1 of 4 treatments, then averaged to get mean response (and variance). Blocks contain the same combinations with different individuals subjected to the same 1 of 4 treatment, but each has randomly assigned placement of the same species and treatments as the other blocks, providing replication. I am not interested in change over time for this experiment, just multiple observations to take environmental variability into account. – Lori Sep 27 '12 at 17:00
If you model measurements repeated over time, you need to consider autocorrelation. That's the reason why I usually use lme from package nlme. – Roland Nov 2 '12 at 8:07
Thanks, Roland. I did deal with autocorrelation with an appropriate underlying covariance structure. I need to migrate from lme() to lmer(). – Lori Nov 2 '12 at 12:18

## migrated from stackoverflow.comOct 2 '12 at 19:16

First, two pre-analysis suggestions:

1. I would treat the units as individual observations without averaging.
2. If you're going to want to say that the species responded differently to the treatments, you'll need the interaction terms, so I wouldn't do the analyses separately (though I can also imagine good reasons for doing them separately).

I think of the random effects specification as (Within_Obs_Factor | Observational_Unit). The idea is that each Observational Unit has some random deviation from the group mean and has some random difference in response to the within-unit manipulation. Since both species and treatment were manipulated between plants, I would not put them in the random effects that way. As far as I can tell, the only factor that changed within observational unit was time (the same plants were observed each week). So, my suggestion would be a model like this:

lmer(PN ~ Spp*Trt + (Week | Unit), data=Expt)


If you'd like to stick with the averaging and analyzing species separately, I think that would mean something like:

lmer(meanPN ~ Trt + (Week | Tub), data=SumExpt, weights=1/varPN)


I'm not exactly sure how Block fits into your design, so I'm not sure where it belongs.

-
 Thanks, Dan. I averaged within the "tub" to avoid issues of psuedo-replication, but I'll revisit that decision. It is the block that provides the replicate; blocks are located separately from one another. I think that would make my statement: lmer(meanPN ~ Trt*Rep + (Week | Tub), data=SumExpt, weights=1/varPN). If, however, the blocks are randomly located in different geographies, it would need to be treated as a random variable - would that just be (1|Rep)? – Lori Sep 27 '12 at 18:08 Since treatment varies within-block, you probably should use the "maximal" random effect structure: (Trt*Week | Rep), though the models don't always converge with this structure, so you might need to simplify: (Trt + Week | Rep) or (Trt | Block) + (Week | Rep). Also, if Rep is just a random unit of replication or observation, then it shouldn't be in your fixed effects. – Dan M. Sep 27 '12 at 18:25 All treatments (a fixed effect) are represented in all blocks. I have a schematic of this that would be most helpful if I could post it :) Again, thanks for your help! – Lori Sep 27 '12 at 19:25