A two-way ANOVA is used to determine whether or not there is a statistically significant difference between the means of three or more independent groups that have been split on two variables (sometimes called “factors”).
This tutorial provides a step-by-step example of how to perform a two-way ANOVA in SAS.
Step 1: Create the Data
Suppose a botanist wants to know whether or not plant growth is influenced by sunlight exposure and watering frequency.
She plants 30 seeds and lets them grow for one month under different conditions for sunlight exposure and watering frequency. After one month, she records the height of each plant. The results are shown below:
We can use the following code to create this dataset in SAS:
/*create dataset*/ data my_data; input water $ sunlight $ height; datalines; daily low 6 daily low 6 daily low 6 daily low 5 daily low 6 daily med 5 daily med 5 daily med 6 daily med 4 daily med 5 daily high 6 daily high 6 daily high 7 daily high 8 daily high 7 weekly low 3 weekly low 4 weekly low 4 weekly low 4 weekly low 5 weekly med 4 weekly med 4 weekly med 4 weekly med 4 weekly med 4 weekly high 5 weekly high 6 weekly high 6 weekly high 7 weekly high 8 ; run;
Step 2: Perform the Two-Way ANOVA
Next, we’ll use proc ANOVA to perform the two-way ANOVA:
/*perform two-way ANOVA*/ proc ANOVA data=my_data; class water sunlight; model height = water sunlight water*sunlight; means water sunlight / tukey cldiff; run;
Step 3: Interpret the Results
The first table we want to analyze in the results is the ANOVA table:
From this table we can see:
- The p-value for water: .0005
- The p-value for sunlight: <.0001
- The p-value for the interaction between water and sunlight: .1207
This tells us that both water and sunlight are statistically significant predictors of plant height and that there is no statistically significant interaction effect between water and sunlight.
Next, we can look at the results of the Tukey post-hoc tests to determine which levels of water and sunlight are statistically significantly different.
First, we’ll look at the Tukey post-hoc comparisons for water:
From the output we can see that the mean difference in height between plants that were watered daily vs. weekly was 1.0667 inches.
The 95% confidence interval for the difference in mean height is [.5163, 1.6170]. This means we’re 95% confident that the true difference in mean height between plants watered daily and plants watered weekly is between .5163 inches and 1.6170 inches.
First, we’ll look at the Tukey post-hoc comparisons for sunlight:
To tell which group means are different, we must look at which pairwise comparisons have stars (***) next to them.
From the table we can see that the following group means are statistically significantly different:
- High sunlight vs. Low sunlight (95% C.I. = [.8844, 2.5156])
- High sunlight vs. Medium sunlight (95% C.I. = [1.2844, 2.9156])
Step 4: Report the Results
Lastly, we can report the results of the two-way ANOVA:
A two-way ANOVA was performed to analyze the effect of watering frequency and sunlight exposure on plant growth.
A two-way ANOVA revealed that there was not a statistically significant interaction between the effects of watering frequency and sunlight exposure (p = .1207).
Simple main effects analysis showed that watering frequency had a statistically significant effect on plant growth (p = .0005).
Simple main effects analysis showed that sunlight exposure also had a statistically significant effect on plant growth (p < .0001).
The following tutorials provide additional information about two-way ANOVAs: