ANOVA, ANCOVA and Fixed, Random and Mixed Effects
CSIR NET statistics: one-way and two-way ANOVA, expected mean squares, fixed, random and mixed effects models, variance components and ANCOVA.
- 19 min
On this page · 13 sections
Prerequisites
- Gauss–Markov Models, BLUE and Linear Hypotheses: estimable contrasts and the general F test, which ANOVA applies.
- Quadratic Forms: every sum of squares here is a quadratic form, and its rank is its degrees of freedom.
- Experimental Design, Sampling and Data: randomisation, replication and blocking, the ideas ANOVA formalises.
The Hook: Three Fertilisers, or Three of Many?
One-Way ANOVA (Fixed Effects)
with \( N = \sum n_i \). The \( \alpha_i \) are fixed unknown constants. Only \( \mu + \alpha_i \) and contrasts \( \sum c_i\alpha_i \) (\( \sum c_i = 0 \)) are estimable; the side condition \( \sum n_i\alpha_i = 0 \) is often imposed to make a solution unique.
Write \( \bar y_{i\cdot} \) for the group means and \( \bar y_{\cdot\cdot} \) for the grand mean. The identity \( y_{ij} - \bar y_{\cdot\cdot} = (\bar y_{i\cdot} - \bar y_{\cdot\cdot}) + (y_{ij} - \bar y_{i\cdot}) \), squared and summed (the cross term vanishes), gives
$$\underbrace{\sum_{i,j}(y_{ij} - \bar y_{\cdot\cdot})^2}_{\text{SST}} = \underbrace{\sum_i n_i(\bar y_{i\cdot} - \bar y_{\cdot\cdot})^2}_{\text{SSB (treatments)}} + \underbrace{\sum_{i,j}(y_{ij} - \bar y_{i\cdot})^2}_{\text{SSW (error)}}.$$| Source | df | SS | MS | \( E(\text{MS}) \) |
|---|---|---|---|---|
| Treatments | \( k - 1 \) | SSB | \( \text{MSB} = \frac{\text{SSB}}{k - 1} \) | \( \sigma^2 + \frac{\sum n_i(\alpha_i - \bar\alpha)^2}{k - 1} \), \( \bar\alpha = \frac{\sum n_i\alpha_i}{N} \) |
| Error | \( N - k \) | SSW | \( \text{MSE} = \frac{\text{SSW}}{N - k} \) | \( \sigma^2 \) |
| Total | \( N - 1 \) | SST |
Under \( H_0: \alpha_1 = \dots = \alpha_k \), \( F = \frac{\text{MSB}}{\text{MSE}} \sim F_{k - 1, N - k} \). Large F rejects. Here \( \text{SSE}_H = \text{SST} \) and \( \text{SSE} = \text{SSW} \), so this is the general linear hypothesis test with \( q = k - 1 \), \( r = k \).
Multiple comparisons. A significant F says some contrast is non-zero, not which. The BLUE of \( \alpha_i - \alpha_{i'} \) is \( \bar y_{i\cdot} - \bar y_{i'\cdot} \) with variance \( \sigma^2\left(\frac{1}{n_i} + \frac{1}{n_{i'}}\right) \), estimated with MSE on \( N - k \) df. Simultaneous procedures (Tukey for pairwise differences, Scheffé for all contrasts, Bonferroni for a few planned ones) control the family-wise error rate.
Assumptions in order of how much they matter: independence, equal variances (check with residual plots or a test such as Bartlett’s or Levene’s), normality (the F test is fairly robust to it with balanced groups).
Two-Way ANOVA
One observation per cell (randomised block design)
\( y_{ij} = \mu + \alpha_i + \beta_j + \varepsilon_{ij} \), \( i = 1, \dots, a \), \( j = 1, \dots, b \). With one observation per cell the interaction cannot be separated from error.
| Source | df | SS |
|---|---|---|
| A (treatments) | \( a - 1 \) | \( b\sum_i(\bar y_{i\cdot} - \bar y_{\cdot\cdot})^2 \) |
| B (blocks) | \( b - 1 \) | \( a\sum_j(\bar y_{\cdot j} - \bar y_{\cdot\cdot})^2 \) |
| Error | \( (a - 1)(b - 1) \) | \( \sum(y_{ij} - \bar y_{i\cdot} - \bar y_{\cdot j} + \bar y_{\cdot\cdot})^2 \) |
| Total | \( ab - 1 \) |
With interaction (n observations per cell, n ≥ 2)
\( y_{ijk} = \mu + \alpha_i + \beta_j + (\alpha\beta)_{ij} + \varepsilon_{ijk} \), \( k = 1, \dots, n \).
| Source | df |
|---|---|
| A | \( a - 1 \) |
| B | \( b - 1 \) |
| AB | \( (a - 1)(b - 1) \) |
| Error | \( ab(n - 1) \) |
| Total | \( abn - 1 \) |
Fixed, Random and Mixed Effects
| Model | Levels of the factor | Inference about | Hypothesis |
|---|---|---|---|
| fixed | chosen deliberately, all of interest | those levels only | \( \alpha_1 = \dots = \alpha_a \) (or all \( \alpha_i = 0 \)) |
| random | a random sample from a population of levels | the population of levels | \( \sigma_\alpha^2 = 0 \) |
| mixed | some factors fixed, some random | fixed means and variance components | both kinds |
One-way random effects
all \( a_i \) independent of all \( \varepsilon_{ij} \). Then \( \operatorname{Var}(y_{ij}) = \sigma_a^2 + \sigma^2 \), and two observations in the same group are correlated: \( \operatorname{Cov}(y_{ij}, y_{ij'}) = \sigma_a^2 \) for \( j \ne j' \).
With \( n \) observations per group:
$$E(\text{MSB}) = \sigma^2 + n\sigma_a^2, \qquad E(\text{MSE}) = \sigma^2.$$- The test of \( H_0: \sigma_a^2 = 0 \) uses the same \( F = \frac{\text{MSB}}{\text{MSE}} \sim F_{k - 1, k(n - 1)} \).
- ANOVA (method-of-moments) estimates: \( \hat\sigma^2 = \text{MSE} \), \( \hat\sigma_a^2 = \frac{\text{MSB} - \text{MSE}}{n} \). The second is unbiased but can be negative; it is then usually truncated at 0.
- Intraclass correlation: \( \rho_I = \frac{\sigma_a^2}{\sigma_a^2 + \sigma^2} \), the correlation between two observations in the same group.
For the worked example above, read as random effects: \( \hat\sigma_a^2 = \frac{28/3 - 2/3}{4} = \frac{13}{6} \), \( \hat\sigma^2 = \frac{2}{3} \), and \( \hat\rho_I = \frac{13/6}{13/6 + 4/6} = \frac{13}{17} \approx 0.76 \).
Two-way expected mean squares (balanced, n per cell)
This table decides the F ratios. Each F test puts over the numerator the mean square whose expectation equals the numerator’s expectation when \( H_0 \) is true.
| Mean square | A, B both fixed | A, B both random | A fixed, B random (restricted model) |
|---|---|---|---|
| MSA | \( \sigma^2 + \frac{bn\sum\alpha_i^2}{a - 1} \) | \( \sigma^2 + n\sigma_{\alpha\beta}^2 + bn\sigma_\alpha^2 \) | \( \sigma^2 + n\sigma_{\alpha\beta}^2 + \frac{bn\sum\alpha_i^2}{a - 1} \) |
| MSB | \( \sigma^2 + \frac{an\sum\beta_j^2}{b - 1} \) | \( \sigma^2 + n\sigma_{\alpha\beta}^2 + an\sigma_\beta^2 \) | \( \sigma^2 + an\sigma_\beta^2 \) |
| MSAB | \( \sigma^2 + \frac{n\sum(\alpha\beta)_{ij}^2}{(a - 1)(b - 1)} \) | \( \sigma^2 + n\sigma_{\alpha\beta}^2 \) | \( \sigma^2 + n\sigma_{\alpha\beta}^2 \) |
| MSE | \( \sigma^2 \) | \( \sigma^2 \) | \( \sigma^2 \) |
(Fixed effects satisfy \( \sum\alpha_i = \sum\beta_j = 0 \) and the interactions sum to zero over each index.)
| Test | Fixed | Random | Mixed (A fixed, B random, restricted) |
|---|---|---|---|
| A | MSA / MSE | MSA / MSAB | MSA / MSAB |
| B | MSB / MSE | MSB / MSAB | MSB / MSE |
| AB | MSAB / MSE | MSAB / MSE | MSAB / MSE |
graph TD
A["Which F ratio?"] --> B["Write E(MS) for every line"]
B --> C["For the effect tested, find the MS whose
expectation equals E(numerator) under H0"]
C --> D{"Is a random factor
crossed with it?"}
D -->|"no (all fixed)"| E["Denominator: MSE"]
D -->|"yes"| F["Denominator: MS of the interaction
with that random factor"]Analysis of Covariance (ANCOVA)
ANCOVA combines ANOVA with regression on a concomitant variable (covariate) \( x \) that is measured before treatment and is not affected by it, such as initial weight in a feeding trial.
with a common slope \( \beta \) in every group (the homogeneity-of-slopes assumption).
Write \( E_{xx}, E_{xy}, E_{yy} \) for the within-group (error) sums of squares and products, and \( T_{xx}, T_{xy}, T_{yy} \) for the total ones (about the grand means).
| Quantity | Formula | df |
|---|---|---|
| pooled within-group slope | \( \hat\beta = \frac{E_{xy}}{E_{xx}} \) | |
| adjusted error SS | \( \text{SSE}' = E_{yy} - \frac{E_{xy}^2}{E_{xx}} \) | \( N - k - 1 \) |
| adjusted total SS | \( T_{yy} - \frac{T_{xy}^2}{T_{xx}} \) | \( N - 2 \) |
| adjusted treatment SS | adjusted total minus adjusted error | \( k - 1 \) |
| adjusted mean of group \( i \) | \( \bar y_{i\cdot} - \hat\beta(\bar x_{i\cdot} - \bar x_{\cdot\cdot}) \) |
The test of equal adjusted treatment effects is \( F = \frac{\text{adjusted treatment SS}/(k - 1)}{\text{SSE}'/(N - k - 1)} \sim F_{k - 1, N - k - 1} \). One degree of freedom is spent on the slope.
ANCOVA does two jobs: it reduces error variance (when \( x \) and \( y \) are correlated within groups) and it removes bias from groups that differ in \( x \). It is valid only if the covariate is unaffected by the treatment and the slopes are equal; test equality of slopes first by fitting separate slopes and using the general F test.
Memory Tricks
- df add up like the SS. One-way: \( (k - 1) + (N - k) = N - 1 \). Two-way with interaction: \( (a - 1) + (b - 1) + (a - 1)(b - 1) + ab(n - 1) = abn - 1 \).
- “Divide by the line just below in the E(MS) ladder.” The denominator is the mean square whose expectation is the numerator’s expectation minus the term being tested.
- Random factor crossed with A: test A against the interaction. Fixed-only designs always use MSE.
- Variance component = (difference of mean squares) / (its coefficient). \( \hat\sigma_a^2 = \frac{\text{MSB} - \text{MSE}}{n} \); in two-way random, \( \hat\sigma_\alpha^2 = \frac{\text{MSA} - \text{MSAB}}{bn} \).
- ANCOVA spends one df on the slope. Error df \( N - k - 1 \).
Don’t Confuse
| This | Is not this | The difference |
|---|---|---|
| fixed effect: \( H_0: \alpha_i \) all equal | random effect: \( H_0: \sigma_a^2 = 0 \) | the one-way F statistic is the same; the inference target differs |
| \( E(\text{MSB}) = \sigma^2 + n\sigma_a^2 \) (random) | \( \sigma^2 + \frac{n\sum\alpha_i^2}{k - 1} \) (fixed) | variance component versus sum of squared fixed effects |
| test A against MSE | test A against MSAB | MSE when every factor is fixed; MSAB when B is random |
| error df \( (a - 1)(b - 1) \) (one per cell) | error df \( ab(n - 1) \) (n per cell) | with one observation per cell, interaction and error are confounded |
| ANCOVA error df \( N - k - 1 \) | ANOVA error df \( N - k \) | one df for the common slope |
| adjusted mean | raw group mean | adjusted mean removes \( \hat\beta(\bar x_{i\cdot} - \bar x_{\cdot\cdot}) \) |
| \( \hat\sigma_a^2 < 0 \) | an arithmetic error | it happens when MSB < MSE; truncate at 0 |
Common Mistakes
Practice
All questions below are original practice questions written for this page. They are not from any CSIR NET paper. In Level 3, as in Part C, one or more options may be correct.
Level 1: Foundation
- A one-way ANOVA has 5 groups and 30 observations in all. Give the treatment and error degrees of freedom.
- In the one-way random-effects model with \( n \) observations per group, what is \( E(\text{MSB}) \)?
- Which assumption about slopes does the standard one-way ANCOVA make?
Answers
- Treatments \( 5 - 1 = 4 \); error \( 30 - 5 = 25 \).
- \( \sigma^2 + n\sigma_a^2 \).
- A common slope \( \beta \) in all groups (homogeneity of regression slopes).
Level 2: Part B Style
Practice Q1. Three groups of four observations: A: 4, 5, 6, 5; B: 7, 8, 9, 8; C: 5, 6, 7, 6. The one-way ANOVA F statistic is:
(a) 7 (b) 9.33 (c) 14 (d) 28
Answer: (c)
\( \text{SSB} = \frac{56}{3} \) on 2 df, \( \text{MSB} = \frac{28}{3} \); \( \text{SSW} = 6 \) on 9 df, \( \text{MSE} = \frac{2}{3} \). \( F = \frac{28/3}{2/3} = 14 \). Option (b) is MSB itself; (d) uses SSB in place of MSB.
Practice Q2. A two-way ANOVA with interaction has \( a = 3 \) levels of A, \( b = 4 \) levels of B and \( n = 2 \) observations per cell. The interaction and error degrees of freedom are:
(a) 6 and 12 (b) 6 and 11 (c) 12 and 6 (d) 5 and 12
Answer: (a)
Interaction \( (3 - 1)(4 - 1) = 6 \); error \( ab(n - 1) = 12 \cdot 1 = 12 \). Check: \( 2 + 3 + 6 + 12 = 23 = abn - 1 \).
Practice Q3. In a one-way random-effects model with 5 observations per group, \( \text{MSB} = 50 \) and \( \text{MSE} = 10 \). The ANOVA estimate of the intraclass correlation is:
(a) 0.2 (b) 0.44 (c) 0.8 (d) 0.5
Answer: (b)
\( \hat\sigma_a^2 = \frac{50 - 10}{5} = 8 \), \( \hat\sigma^2 = 10 \), \( \hat\rho_I = \frac{8}{8 + 10} = \frac{4}{9} \approx 0.44 \).
Practice Q4. In a balanced two-way model with interaction in which both factors are random, the F statistic for testing \( \sigma_\alpha^2 = 0 \) is:
(a) MSA / MSE (b) MSA / MSAB (c) MSAB / MSE (d) MSA / MSB
Answer: (b)
\( E(\text{MSA}) = \sigma^2 + n\sigma_{\alpha\beta}^2 + bn\sigma_\alpha^2 \) and \( E(\text{MSAB}) = \sigma^2 + n\sigma_{\alpha\beta}^2 \). They are equal exactly when \( \sigma_\alpha^2 = 0 \), so MSAB is the denominator.
Level 3: Part C Style
Practice Q5. Consider the one-way random-effects model \( y_{ij} = \mu + a_i + \varepsilon_{ij} \), \( i = 1, \dots, k \), \( j = 1, \dots, n \), with \( a_i \sim N(0, \sigma_a^2) \) and \( \varepsilon_{ij} \sim N(0, \sigma^2) \), all independent. Which statements are true?
(a) \( y_{11} \) and \( y_{12} \) are independent. (b) \( \operatorname{Cov}(y_{11}, y_{12}) = \sigma_a^2 \). (c) \( \frac{\text{MSB} - \text{MSE}}{n} \) is an unbiased estimator of \( \sigma_a^2 \) that can take negative values. (d) Under \( H_0: \sigma_a^2 = 0 \), \( \frac{\text{MSB}}{\text{MSE}} \sim F_{k - 1, k(n - 1)} \).
Answer: (b), (c) and (d)
- (a) False. They share \( a_1 \).
- (b) True. \( \operatorname{Cov}(\mu + a_1 + \varepsilon_{11}, \mu + a_1 + \varepsilon_{12}) = \operatorname{Var}(a_1) = \sigma_a^2 \).
- (c) True. \( E(\text{MSB} - \text{MSE}) = n\sigma_a^2 \). It is negative whenever MSB < MSE, which has positive probability.
- (d) True. Under \( H_0 \) the model is iid \( N(\mu, \sigma^2) \) and the fixed-effects null distribution applies.
Practice Q6. In a one-way ANCOVA with two groups of three, group 1 has \( x = 1, 2, 3 \), \( y = 2, 4, 5 \) and group 2 has \( x = 3, 4, 5 \), \( y = 5, 6, 8 \). Which statements are true?
(a) The pooled within-group slope is \( \frac{3}{2} \). (b) The adjusted error sum of squares is \( \frac{1}{3} \), on 3 degrees of freedom. (c) The adjusted mean of group 1 exceeds that of group 2. (d) The ANCOVA F statistic for treatments exceeds the one-way ANOVA F statistic computed on \( y \) alone.
Answer: (a), (b) and (c)
- (a) True. \( E_{xy} = 3 + 3 = 6 \), \( E_{xx} = 2 + 2 = 4 \).
- (b) True. \( E_{yy} - \frac{E_{xy}^2}{E_{xx}} = \frac{28}{3} - 9 = \frac{1}{3} \); df \( 6 - 2 - 1 = 3 \).
- (c) True. Adjusted means \( \frac{31}{6} \) and \( \frac{29}{6} \). Group 1’s raw mean is lower (\( \frac{11}{3} < \frac{19}{3} \)), but it started with smaller \( x \).
- (d) False. ANCOVA \( F = 0.6 \); ANOVA on \( y \) gives \( F = \frac{32}{7} \approx 4.57 \). Adjustment removed most of the apparent difference.
Practice Q7. A balanced two-way experiment has factor A fixed with \( a \) levels, factor B random with \( b \) levels, \( n \ge 2 \) replicates per cell, and the restricted mixed model. Which statements are true?
(a) The main effect of A is tested with MSA / MSAB. (b) The variance component of B is tested with MSB / MSE. (c) The interaction is tested with MSAB / MSE. (d) The error degrees of freedom are \( (a - 1)(b - 1) \).
Answer: (a), (b) and (c)
- (a) True. \( E(\text{MSA}) = \sigma^2 + n\sigma_{\alpha\beta}^2 + \frac{bn\sum\alpha_i^2}{a - 1} \), which equals \( E(\text{MSAB}) \) under \( H_0 \).
- (b) True. In the restricted model \( E(\text{MSB}) = \sigma^2 + an\sigma_\beta^2 \). (In the unrestricted model it would be MSB / MSAB.)
- (c) True. \( E(\text{MSAB}) = \sigma^2 + n\sigma_{\alpha\beta}^2 \) versus \( E(\text{MSE}) = \sigma^2 \).
- (d) False. Error df are \( ab(n - 1) \); \( (a - 1)(b - 1) \) is the interaction df.
Quick Revision Table
| Idea | Fact |
|---|---|
| One-way | SST = SSB + SSW; df \( N - 1 = (k - 1) + (N - k) \) |
| One-way F | \( \frac{\text{MSB}}{\text{MSE}} \sim F_{k - 1, N - k} \) |
| Randomised block | error df \( (a - 1)(b - 1) \); no interaction test |
| Two-way with \( n \) per cell | A: \( a - 1 \), B: \( b - 1 \), AB: \( (a - 1)(b - 1) \), error: \( ab(n - 1) \) |
| Random one-way | \( E(\text{MSB}) = \sigma^2 + n\sigma_a^2 \); \( \hat\sigma_a^2 = \frac{\text{MSB} - \text{MSE}}{n} \) (may be negative) |
| Intraclass correlation | \( \frac{\sigma_a^2}{\sigma_a^2 + \sigma^2} \) |
| Fixed two-way | every effect over MSE |
| Random two-way | A, B over MSAB; AB over MSE |
| Mixed (A fixed, B random) | A over MSAB; AB over MSE; B over MSE (restricted) or MSAB (unrestricted) |
| ANCOVA slope | \( \hat\beta = \frac{E_{xy}}{E_{xx}} \); error SS \( E_{yy} - \frac{E_{xy}^2}{E_{xx}} \), df \( N - k - 1 \) |
| Adjusted mean | \( \bar y_{i\cdot} - \hat\beta(\bar x_{i\cdot} - \bar x_{\cdot\cdot}) \) |
Key Takeaways
What’s Next
- Simple, Multiple and Logistic Regression: the regression half of ANCOVA, with diagnostics.
- Multivariate Normal, Wishart and Quadratic Forms: Cochran’s theorem, which makes the ANOVA sums of squares independent chi-squares.
- Gauss–Markov Models, BLUE and Linear Hypotheses: the general F test behind every table on this page.
- Back to the Linear Models and Multivariate Analysis chapter overview.