# Specifying mixed model in lme/r for three-way experiment with two random effects

I have been searching for the answer online without success.I have a full factorial design with temperature (Cold and Warm), predator (Yes/No), and aphid species (A, B and C) as fixed effects (12 treatments in total). I did 3 replicates of each treatment at 5 different dates (a total of 15 replicates per treatment). This was a lab experiment performed with only two growth chambers (corresponding each to one temperature) which were inverted at each date (for example: Date 1, chamber 1: Cold, chamber 2: Warm; Date 2, chamber 1: Warm, chamber 2: Cold;....). The response variable is aphid abundance.

Date is a random effect but I am not sure how should I deal with the temperature/chamber component and also the fact that predator and species are nested in the temperature regime:

m1.nlme = lme(aphid ~ temperature*predator*species,
method="REML",
random = ~ 1|date, data = My.Data)

m2.nlme = lme(aphid ~ temperature*predator*species,
method="REML",
random = ~ 1|date/temperature, data = My.Data)

m3.nlme = lme(aphid ~ temperature*predator*species,
method="REML",
random = ~ 1|date/temperature/predator/species, data = My.Data)


I am a bit confuse with all the things I red online and do not know which one of these models is the best for these data?

• In model 2 and three you model some variables as both fixed and random (e.g. temperature). What do you think are the random effects and how are they related (nested)? Chamber and date? – Ivo Dec 2 '15 at 10:25
• In models two and three, the random effect would be date + interactions between date and temperature (for model 2), predator, and species (for model 3). – Arno Dec 2 '15 at 11:17
• OK. First, a variable is either a fixed or a random effect, not both. With a mixed model you account for structural dependencies that result from the design in the study. I would say that date and chamber are both random effects. I would also say that you are trying to find the effect of temperature, predator and species so they are fixed effects. I can't come up with a reason to model interaction between date and temperature (mainly because one is random and the other is fixed). – Ivo Dec 2 '15 at 14:01

So, you want to model one effect, date (see comments below). And three predictors. Based on what I know now I would say this is the way to go:

m.nlme = lmer(aphid ~ temperature*predator*species + 1|date,
data = My.Data)


This model assumes no nested structure. What part of the design makes you want to use a nested structure?

• Thanks for your answer. yes it seems that it is the correct model. lme is not working nicely for crossed random effects but the function lmer is able to handle this gm1 <- lmer(aphid~ temperature*predator*species+(1|date)+(1|chamber),data = My.Data) I have another data set for which we did not inverted growth chamber between each date. So 1 chamber = 1 temperature. What would be the correct model in this case? only date as a random effect? – Arno Dec 2 '15 at 14:43
• Hmm. Yes. In that case temperature and chamber are not distinguishable. So if you find and effect for temperature it possibly (partly) explained by the random chamber effect. – Ivo Dec 2 '15 at 15:18
• Yes I agree but, in this case, would you still keep chamber as a random effect as in gm1 above? or drop it as it not very informative? Thanks a lot for your answers. it's really helping me. – Arno Dec 2 '15 at 15:35
• I'm not a 100% sure on this point. I expect that if you include the random effect for chamber the fixed temperature effect would still be estimable and the random effect will have less variance than when you would not include temperature. On the other hand, you can run the model (with both effects) but the interpretation will just be limited due to the design of the study. You might want to start another topic for this question. – Ivo Dec 3 '15 at 16:24
• A similar question was asked here: stats.stackexchange.com/questions/71587/… – Ivo Dec 3 '15 at 16:33