# Repeated measures ANOVA in R: Error(Subject) vs. Error(Subject/Day)

How should these two models be interpreted differently? Specifically, what is the circumstance where you would run one over the other?

aov(Temperature~Day+Error(Subject))
aov(Temperature~Day+Error(Subject/Day))


We'll use an example where I measured the temperature of 10 people once every day for a week. My main interest is to see if the temperature measurements change significantly day-to-day, and I am not interested in the longitudinal trend from Monday to Sunday.

• do you have replication per individual&day? Commented Nov 23, 2016 at 21:57
• Every person is measured once per day.... 7 measures per person, 70 measures total. Does that help? Commented Nov 23, 2016 at 22:01
• Yes, see my answer below. Commented Nov 24, 2016 at 0:25
• Commented Jun 21, 2017 at 20:47

Depending on the contrasts you are using, the R command

aov(Temperature~Day+Error(Subject))


fits a model like

$$y_{ij} = \mu + \beta_j + b_i + \epsilon_{ij},$$

where $y_{ij}$ is the response value for the $i$th individual at the $j$th period (day), $\mu$ is global mean, $\beta_j$ is the effect of $j$th day, $b_i\sim N(0,\sigma_b^2)$ is the Gaussian random effect or random intercept for the $i$th individual and $\epsilon_{ij}\sim N(0,\sigma^2)$ is the Gaussian residual term. The unknown parameters are $(\mu, \beta_j,\sigma_b^2, \sigma^2)$.

On the other hand, the command

aov(Temperature~Day+Error(Subject/Day))


fits the model

$$y_{ijk} = \mu + \beta_j + b_i + b_{ij} + \epsilon_{ijk},$$

where $b_{ij}\sim N(0, \sigma_1^2)$ is a Gaussian random individual-period interaction term. As you can see from the expression, to estimate also $\sigma_1^2$ you need to have replications for each $i$ and $j$, that's the reason for the third index $k$.

• So in a very loose (probably naive) way, is aov(Temperature~Day+Error(Subject)) analogous to lm(Temperature~Day+Subject)? Also, and this is probably obvious for many reasons, how does aov(Temperature~Day+Error(Subject/Day)), differ from the mixed model lmer(Temperature~Day + (1|Subject))? Commented Nov 24, 2016 at 13:38
• aov(Temperature~Day+Error(Subject)) vs lm(Temperature~Day+Subject): the former has two variance components, one for the random effects at the Subject level and one for the residuals. The latter has only one residual variance, no random effects but has fixed effects for Subject. Commented Nov 25, 2016 at 9:10
• lmer(Temperature~Day + (1|Subject)) is theoretically identical to aov(Temperature~Day+Error(Subject)) Commented Nov 25, 2016 at 9:11
• aov(Temperature~Day+Error(Subject/Day)) includes a further random effect, which is an interaction between Subject and Day. So this model has three variance components. It can be estimated iff you have replication for each Day and Subject, which, as far as I understood you do not! Commented Nov 25, 2016 at 9:13
• +1. @AtMac: aov(Temperature~Day+Error(Subject/Day)) corresponds to lmer(Temperature~Day+(1|Subject)+(1|Subject:Day) which is the same as lmer(Temperature~Day+(1|Subject/Day). Commented Jun 28, 2017 at 9:09