Section 28 ANOVA Table

28.1 Analysis of Variance Table


\[ \large fm \leftarrow lm(SBP \sim Group, \space data=BP) \]

\[ \large anova(fm) \]


Df Sum Sq Mean Sq F value Pr(>F)
Group 3 1521.638 507.2128 7.4983 5e-04
Residuals 36 2435.184 67.6440 NA NA
Total 39 3956.822 NA NA NA

28.2 Explanation


Degrees of freedom (df)

\(\large n\) = observations per group

\(\large g\) = number of groups

Group df = \(\large (g - 1)\)

Residual df = \(\large g * (n - 1)\)

Total df = Treatment df + Residual df = \(\large (g * n) - 1\)


Sum of Squares due to Treatment (Group)

  1. For each group calculate: n * (Group mean - overall mean)2

  2. Add the values for the different groups together

\[ \large SST = n\sum\limits_{i=1}^{g} (\bar{y_i}-\bar{y})^2 \]


Sum of Squares due to Error

Residual Sum of Squares

For each observation calculate:

  1. (Observed value - group mean)2

  2. Add the values for the different observations together

\[ \large SSE = \sum\limits_{i=1}^{g} \sum\limits_{j=1}^{n} (y_{ij}-\bar{y_i})^2 \]


Total Sum of Squares = SS due to Treatment + SS due to Error


Mean Squares

Mean square = Sum of squares / degrees of freedom

\(\large MS = SS / df\)


F-value (Variance Ratio)

F value = Treatment MS / Residual MS


Pr(>F)

P-value: the probability of obtaining a variance ratio this large under the null hypothesis that the treatment means are all equal.

Under the null hypothesis the variance ratio has an F distribution.


28.3 Exercise

  • Use the base R functions to calculate the following according to the formula presented above

    • df, SS, MS for Group, Error and Total

    • F-statistic and corresponding probability

    • Prepare a data.frame with all these values