Section 29 ANOVA Table: Simple R implementation
29.1 Analysis of Variance Table
fm←lm(SBP∼Group, data=BP)
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 |
29.2 Explanation
Degrees of freedom (df)
n = observations per group
g = number of groups
Group df = (g−1)
Residual df = g∗(n−1)
Total df = Treatment df + Residual df = (g∗n)−1
Sum of Squares due to Treatment (Group)
For each group calculate: n * (Group mean - overall mean)2
Add the values for the different groups together
SST=ng∑i=1(¯yi−ˉy)2
y.bar <- mean(BP$SBP, na.rm = TRUE)
yi.bar <- tapply(BP$SBP, INDEX = BP$Group, FUN = mean, na.rm = TRUE)
SST <- n * sum((yi.bar - y.bar)^2)
Sum of Squares due to Error
Residual Sum of Squares
For each observation calculate:
(Observed value - group mean)2
Add the values for the different observations together
SSE=g∑i=1n∑j=1(yij−¯yi)2
Total Sum of Squares = SS due to Treatment + SS due to Error
Mean Squares
Mean square = Sum of squares / degrees of freedom
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.