Section 19 Two-way ANOVA: Model Assumptions
Residual
\[ \Huge \hat{\epsilon_{ijk}} = y_{ijk} - \hat{y_{ij}} \]
19.1 Assumptions
The data are independent samples from normal distributions
The variability within each treatment group is identical (\(\sigma^2\))
Properties of residual as \(\large \epsilon_{ij} \sim NID(0, \sigma^2)\)
Various diagnostic tools are available in order to check these assumptions:
- Histogram of residuals: should be approximately $\sim NID(0, \sigma^2)$ - QQ plot should show the distribution of residual as Normal - Residuals versus fitted values - Residuals versus explanatory variables - Residuals versus any other variables not included in the model
All these plots should show no patterns or trend
Test for homogeneity of variance
- `fligner.test(SBP ~ Group, data=BP)` - `bartlett.test(SBP ~ Group, data=BP)` - Also, `var.test` to perform an F test to compare the variances of two samples from normal populations.
19.3 Customised residual plots
19.3.2 Histogram of residuals
hist(x=res, freq = TRUE,
main = '',
xlab = 'Residuals',
ylab = 'Frequency',
axes = TRUE,
col = 'lightblue',
lty = 1, border = 'purple')
hist(x=res, breaks=10, freq = FALSE,
xlab = 'Residuals',
ylab = 'Density',
axes = TRUE,
col = 'lightblue',
lty = 1, border = 'purple')
lines(density(res), col = 'red', lwd = 2, lty = 1)
19.3.3 QQ plot of residuals
qqnorm(y=res, main='Normal QQ of residuals',
xlab='Theoretical Quantiles',
ylab='Residuals',
col='blue', pch=20)
qqline(y=res, lty=1, lwd=2, col='red')
19.3.4 Scatter plot of residual against fitted value
plot(x=pred, y=res, pch=20, col='purple')
# lo <- loess(res ~ pred)
# lines(predict(lo), col='red', lty=1, lwd=2)
abline(a = 0, b = 0, lty=2, col='red')