# How to write the error term in repeated measures ANOVA in R: Error(subject) vs Error(subject/time)

My question is very closely related to a previous post Specifying the Error() term in repeated measures ANOVA in R. However, I would like to get more insight into how to define the error term.

Suppose I have a two-way repeated ANOVA, The factor for between group effect is the Treatment (control vs. placebo), while Time is the within group effect measured repeatedly over 4 times (T1~T4). Patients ID are recorded as Subject. Here I borrowed the data from an example from the tutorial in http://gjkerns.github.io/R/2012/01/20/power-sample-size.html so the data looks like this

 Time Subject Method      NDI
0min    1     Treat 51.01078
15min   1     Treat 47.12314
48hrs   1     Treat 26.63542
96hrs   1     Treat 20.78196
0min    2     Treat 42.61345
15min   2     Treat 32.77171


To apply ANOVA:

aovComp <- aov(NDI ~ Time*Method + Error(Subject/Time), theData)
summary(aovComp)
Error: Subject
Df Sum Sq Mean Sq F value Pr(>F)
Method     1    113   112.7   0.481  0.491
Residuals 58  13579   234.1

Error: Subject:Time
Df Sum Sq Mean Sq F value  Pr(>F)
Time          3  13963    4654 103.789 < 2e-16 ***
Time:Method   3   1221     407   9.074 1.3e-05 ***
Residuals   174   7803      45


I have also tried the other error term:

aovComp1 <- aov(NDI ~ Time*Method + Error(Subject), theData)
summary(aovComp1)

Error: Subject
Df Sum Sq Mean Sq F value Pr(>F)
Method     1    113   112.7   0.481  0.491
Residuals 58  13579   234.1

Error: Within
Df Sum Sq Mean Sq F value  Pr(>F)
Time          3  13963    4654 103.789 < 2e-16 ***
Time:Method   3   1221     407   9.074 1.3e-05 ***
Residuals   174   7803      45


Can someone help me explaining the differences between these two error terms? If the first term is the correct one, what does the results from the second error term mean?

Update by @amoeba: The two outputs are the same so it seems that in this case there is no difference, but the question remains as to what is the difference in principle. Are Error(subject) and Error(subject/time) always the same thing?

• sorry, I just realized that these two terms give the same results. So I guess they are the same :-) – tiantianchen May 27 '13 at 18:40
• I was hoping for an explanation to this :/ – vipin8169 Mar 28 '17 at 20:14
• All I can gather about the error term is this>> "In a repeated measures design, we need to specify an error term that accounts for natural variation from participant to participant. (E.g., I might react a little differently to scary music than you do because I love zombie movies and you hate them!) We do this with the Error() function: specifically, we are saying that we want to control for that between-participant variation over all of our within-subjects variables." – vipin8169 Mar 28 '17 at 20:29
• (+1) They are equivalent only when there is exactly 1 measurement per each subject/time combination. If there are more measurements per subject/time combination (either simply because measurements were repeated, or because there is another within-subject factor B, in addition to time), then Error(subject) and Error(subject/time) will yield different F- and p-values for time. – amoeba says Reinstate Monica Jun 19 '17 at 9:48
• The same question on SO: stackoverflow.com/questions/37497948 - unfortunately without fully satisfactorily answers either (imho). – amoeba says Reinstate Monica Jun 19 '17 at 11:11

First, subject/time is notation for time nested in subject, and so expands to two parts, subject and the subject:time interaction. So the question more properly becomes, when should one specify the subject:time interaction, and what difference does it make?

Before answering this question, one other important thing to realize is that all models include one additional error term that need not be specified, which is the error term associated with the individual measurements (the lowest level, if you think about this hierarchically).

In this case, the subject:time interaction is that lowest level, which is always included in the model. So using Error(subject) and Error(subject/time) give the same result; the only difference is that in the output, that level of results is called Within for the first and is called subject:time for the second.

However, in cases where there are multiple measurements at each subject/time combination, it is necessary to specify the subject:time interaction, as then that interaction is not at the lowest level.

• (I had an open bounty on this question but it unfortunately ran out yesterday...) +1, but I think this answer sidesteps what may be the central issue here: in the presence of multiple measurements per each subject/time combination, why would we necessarily want to test the effect of time relative to subject:time interaction? This is essentially the content of my question here stats.stackexchange.com/questions/286280, so I would invite any future readers of this thread to look there for conceptual justification. – amoeba says Reinstate Monica Jun 28 '17 at 8:59
• Also, there is a very similar Q and A here: stats.stackexchange.com/questions/247582. – amoeba says Reinstate Monica Jun 28 '17 at 9:11