# Random factor nested in two fixed factors

I have read Random effect nested under fixed effect model in R, but I have a doubt:

My data is on germling survivorship, I have Temperature as a fixed factor (2 levels), pH as a fixed factor (2 levels), and I have tank, which I included to check for tank effect (2 tanks per treatment combination, in a total of 8 tanks).

How can I make a model which nests tank within the temp/pH fixed effect?

From a previous post I read, we could do:

Using aov like this:

a0 <- aov(survivorship ~ pH*temp + Error(tank), data=d)
summary(a0)


or lme like this:

library(nlme)
m1 <- lme(survivorship ~ pH*temp, random=~1|tank, data=d)
anova(m1)


I have tried these two models, but I got two different answers. Can anyone explain why?

Is this correct, by using aov like this, is tank nested in pH:temp interaction?

aov(survivorship ~ pH*temp + Error(tank)

• Shouldn't you do ~1 + pH*temp | tank and Error(tank/(pH*temp))? – Lost in transcription Jun 6 '14 at 14:50
• How many observations do you have in each tank? Is the design balanced? (same number of observations in each tank?) – Placidia Jun 6 '14 at 15:24
• 9 observations per tank. Balanced design. – f_vazpinto Jun 8 '14 at 8:08
• @"Lost in transcription" that formula would be correct if the treatments were nested inside the tanks - but it's the other way around. – Placidia Jun 9 '14 at 14:04

aov and lme are not the same functions. aov is a wrapper for lm, the general linear model function. For balanced designs and one or two random levels, aov can cope with a random term by fitting linear models to different error strata (according to the help files). Significance testing is done using appropriate F statistics.

lme, on the other hand, fits a genuine mixed effects model using maximum likelihood (or REML) to obtain estimates of the parameters of the model. They are not required to give the same estimates.

It is also possible that your formulae are miss-specified, but I can't tell from the information you have supplied in the question. I don't see where there are two levels in the model. You have a 2x2 factorial with two replicates (the tanks) at each treatment level. The "tank effect" is simply the residual error -- unless you are taking several measurements from each tank.

Later

I simulated some data based on the OP's problem: a 2x2 factorial with 2 replicates at each level (the tank) and 9 measurements from each tank. There are 3 ways to analyse these data

1. Use aov and the formula given by the OP
2. Use lme (resp lmer) and the formula given by the OP
3. Take the mean survivorship within each tank and use oav() on the means.

All three methods lead to the same conclusions. The first and the third produce numerically identical F statistics (as they should, given the problem is balanced).

aov and lme give different output. To see the coefficients for pH and temp you need to do coef() on the output of the aov() function. I got identical estimates. The p-values are slightly different, as one would expect given a different model, different estimation and different test statistic.

Notice that you get 7 degrees of freedom in the aov() model. The treatments are randomized to the 8 tanks, so basically, the sample size is 8. Taking repeated measurements in each tank gives a more precise measurement of whatever is going on inside each tank -- which is good -- but in a sense, this is still an experiment in which n=8.

• My experimental design is a 3-way anova, where we have Temperature and ph as fixed factors (2 levels each) and Tank as a random factor. Inside each tank I have 9 replicates where I measured germling survivorship. In this case Tank is nested in the interaction of Temperature and pH. I understand lme and aov are different functions, but then which will be the best one to use...As both of them can be used, I assumed that although different output occur, significant levels will remain...Maybe I have the model wrong... – f_vazpinto Jun 8 '14 at 8:07
• @f_vazpinto I simulated some data with the structure you describe and I've added more specifics to my answer. – Placidia Jun 9 '14 at 13:54
• I have read a little bit more on the subject and because I have balanced design, I will go with aov. But I understand I might have my model wrong. When you said to use the means for each tank, I understood I got something wrong. Inside each tank I have 9 mesocoms, and I am using a mean from measurements from inside the mesocomos, so I have n = 9 within each tank. I think I can do aov(survivorship ~ Temperature * pH + Error (Tank/mesocosm)). What do you think? – f_vazpinto Jun 10 '14 at 10:14
• Also, with this model mesocosm is nested within Tank. My question will be if like this, Tank is nested within the fixed factors? Or because is a balanced design it is not necessary to specify tank nested within the fixed factors!!! – f_vazpinto Jun 10 '14 at 10:30