2024

Two-way ANOVA

  • Two-way ANOVA is used to determine if there are any differences between the means of at least two (but usually three or more) independent groups based on two categorical independent variables.

  • It’s a test for equality of means but it uses variances under the hood to make this determination.

  • ANOVA is an omnibus test. If the test is significant, we know that at least one group is different from the others, but NOT which groups are different.

Example

  • study investigating the effect of sleep deprivation and calorie restriction on cognitive performance.

  • Independent Variable 1: Amount of sleep (categorical with three levels, such as “Full 8 hours,” “4 hours,” and “No sleep”).

  • Independent Variable 2: Amount of calorie restriction (categorical with two levels, such as “less than 1000 calories per day” and “more than 2000 calories per day”).

  • Dependent Variable: Performance on a cognitive task measured by scores on a memory test or reaction times (just needs to be continuous).

Two-way ANOVA Intuition

  • If between-group variation \(>>\) within-group variation \(\rightarrow\) different groups have different means.

  • Two-way ANOVA isn’t as simple as one-way ANOVA because there are many groups for observations to fall between or within.

  • The key is to see that a two-way ANOVA is actually testing three null hypotheses simultaneously

  • The reading goes into more mathematical detail but it can get pretty numbing so we’ll skip it here.

Two-way ANOVA: Hypotheses

  1. Do different levels of factor 1 lead to different outcomes?

  2. Do different levels of factor 2 lead to different outcomes?

  3. Does the effect of factor 1 depend on the level of factor 2?

Factor A Hypotheses

  • Null Hypothesis (\(H_0\)): The means across all levels of factor A are equal:

    \[ \mu_{A1} = \mu_{A2} = \mu_{A3} = \ldots \]

  • Alternative Hypothesis (\(H_1\)): At least one level mean of factor A is different from the others.

Factor B Hypotheses

  • Null Hypothesis (\(H_0\)): The means across all levels of factor B are equal.

    \[ \mu_{B1} = \mu_{B2} = \mu_{B3} = \ldots \]

  • Alternative Hypothesis (\(H_1\)): At least one level mean of factor B is different from the others.

Interaction Hypotheses

  • The interaction hypotheses test whether the effect of one factor is the same at all levels of the other factor.

  • This means checking if the differences between the levels of one factor depend on the level of the other factor:

  • Null Hypothesis (\(H_0\)): The effect of one factor on the response variable is consistent across the levels of the other factor.

    \[( \mu_{ij} - \mu_{i\cdot}) - (\mu_{\cdot j} - \mu_{\cdot\cdot}) = 0 \quad \text{for all } i, j \]

  • \(\mu_{ij}\) is the mean response at the ith level of factor A and the jth level of factor B

  • \(\mu_{i\cdot}\) and \(\mu_{\cdot j}\) are the marginal means of factor A and B respectively

  • \(\mu_{\cdot\cdot}\) is the grand mean.

  • Alternative Hypothesis (\(H_1\)): The effect of one factor on the response variable varies across the levels of the other factor.

Visualising the three null hypotheses

Main effect of factor A

Main effect of factor B

Interaction between A and B

Summary: Main effect and interaction

  • Significant main effects: Group by the factor of interest, average over the other factor, and look for differences in the resulting means.

  • Significant interaction: Group by both factors and look for non-parallel lines.

Two-way ANOVA using ezANOVA

##              y      A      B subject
##          <num> <fctr> <fctr>   <int>
##  1:  0.2234886      1      1       1
##  2:  0.6355615      1      1       2
##  3:  1.9253916      1      1       3
##  4:  0.2257891      1      1       4
##  5: -2.5946238      1      1       5
##  6: -2.6503259      1      1       6
##  7: -0.6881905      1      1       7
##  8:  1.4653949      1      1       8
##  9:  1.5670559      1      1       9
## 10:  3.1426714      1      1      10
## 11:  4.8062265      1      2      11
## 12:  2.9246776      1      2      12
## 13:  2.1163434      1      2      13
## 14:  3.6829297      1      2      14
## 15:  0.2759731      1      2      15
## 16:  2.0585714      1      2      16
## 17:  8.0390576      1      2      17
## 18:  3.1942068      1      2      18
## 19:  6.4309070      1      2      19
## 20: -2.1525916      1      2      20
## 21:  5.5804774      2      1      21
## 22:  5.3637807      2      1      22
## 23:  2.2570139      2      1      23
## 24:  2.2082593      2      1      24
## 25:  3.2863256      2      1      25
## 26: -1.2467564      2      1      26
## 27:  1.3028298      2      1      27
## 28:  1.6526229      2      1      28
## 29:  3.3684937      2      1      29
## 30:  3.5588365      2      1      30
## 31: -1.1190788      2      2      31
## 32:  3.0733603      2      2      32
## 33:  0.6787820      2      2      33
## 34: -2.5527714      2      2      34
## 35:  0.3640345      2      2      35
## 36:  2.9462275      2      2      36
## 37:  2.5259022      2      2      37
## 38:  0.6638712      2      2      38
## 39: -0.6226261      2      2      39
## 40: -2.0516387      2      2      40
##              y      A      B subject

dd[, A := factor(A)]
dd[, B := factor(B)]
dd[, subject := factor(subject)]
ezANOVA(data=dd, dv=y, wid=subject, between=.(A, B))
## Coefficient covariances computed by hccm()
## $ANOVA
##   Effect DFn DFd           F            p p<.05         ges
## 1      A   1  36  0.05728861 0.8121913910       0.001588822
## 2      B   1  36  0.11000158 0.7420655114       0.003046291
## 3    A:B   1  36 13.24277962 0.0008515629     * 0.268928353
## 
## $`Levene's Test for Homogeneity of Variance`
##   DFn DFd      SSn      SSd        F         p p<.05
## 1   3  36 2.752176 69.27299 0.476753 0.7004391

Reporting a two-way ANOVA

  Effect DFn DFd           F            p p<.05          ges
1      A   1  36  0.39357521 0.5343852052       0.0108144147
2      B   1  36  0.03322773 0.8563818866       0.0009221413
3    A:B   1  36 16.15655987 0.0002847749     * 0.3097704279

Results

A two-way analysis of variance was conducted to examine the effects of factors A and B, as well as their interaction (A:B), on the dependent variable. The analysis yielded a non-significant main effect of factor A, \(F(1, 36) = 0.394, p = .534\), with a very small effect size (\(\eta^2_p = 0.011\)). Similarly, the main effect of factor B was also non-significant, \(F(1, 36) = 0.033, p = .856\), with a negligible effect size (\(\eta^2_p = 0.001\)). However, the interaction effect between factors A and B was found to be statistically significant, \(F(1, 36) = 16.157, p < .001\), indicating a substantial effect (\(\eta^2_p = 0.310\)). This suggests that the effect of factor A on the dependent variable depends significantly on the level of factor B.

Assumptions of Two-way ANOVA

  1. Independence: All observations are independent of each other.

  2. Normality: All raw data sampling distributions are normally distributed.

  3. Homogeneity of Variances (Homoscedasticity): All raw data sampling distributions have equal variance.

  4. Measurement Scale: Observed data is continuous and predictors are categorical.