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)

 A: 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


*

*Use aov and the formula given by the OP

*Use lme (resp lmer) and the formula given by the OP

*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.
