Solved – How is degrees of freedom calculated in AOV function for repeated measures anova

anovadegrees of freedomr

I am doing a repeated measures ANOVA using the aov function, looking at the effects of (5) structure, (2) hemisphere and (2) groups on volumes in 59 individuals. Structure and hemispheres are repeated. groups are not.

I understand that if you are using the lmer package to do a repeated measures anova, the degrees of freedom are calculated using the Satterthwaite method. However, I am unclear on what the default method is for calculating degrees of freedom using the aov method. Any help or reference to resources would be helpful!!!

my code:

mixed.ANOVA <- aov(volume ~ group * hemisphere *structure + Error(ID/structure*hemisphere*group), data=volumes.rm )

summary( mixed.ANOVA )


Error: ID
          Df Sum Sq Mean Sq F value   Pr(>F)    
group      1 248997  248997   19.07 5.37e-05 ***
Residuals 57 744049   13053                     
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Error: hemisphere
           Df Sum Sq Mean Sq
hemisphere  1  17064   17064

Error: ID:subfield
                Df   Sum Sq Mean Sq  F value  Pr(>F)    
structure         4 26349556 6587389 2431.282 < 2e-16 ***
group:structure  4    42646   10661    3.935 0.00414 ** 
Residuals      228   617750    2709                     
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Error: ID:hemisphere
                 Df Sum Sq Mean Sq F value Pr(>F)  
group:hemisphere  1   5269    5269   2.998 0.0888 .
Residuals        57 100193    1758             

Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Error: ID:subfield:hemisphere
                           Df Sum Sq Mean Sq F value   Pr(>F)    
hemisphere:structure         4  73722   18431  20.479 1.98e-14 ***
group:hemisphere:structure   4   3223     806   0.895    0.467    
Residuals                 228 205197     900                     
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

I understand that if you are using the lmer package, degrees of freedom are calculated using the Satterthwaite method. However, I am unclear on what the default method is for calculating degrees of freedom using the aov method. Any help or reference to resources would be helpful!!!

Best Answer

As pointed out by Zheyuan Li in the comments the degrees of freedom for the model (as opposed to the residuals) is the number of coefficients. I checked the source code to confirm. Here's the line where they are first created:

 df <- numeric(nterms)

Full source: https://github.com/SurajGupta/r-source/blob/master/src/library/stats/R/aov.R