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 factors.

This tutorial explains how to perform a two-way ANOVA by hand.

**Example: Two-Way ANOVA by Hand**

Suppose a botanist wants to know if plant growth is influenced by sunlight exposure and watering frequency. She plants 40 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:

In the table above, we see that there were five plants grown under each combination of conditions.

For example, there were five plants grown with daily watering and no sunlight and their heights after two months were 4.8 inches, 4.4 inches, 3.2 inches, 3.9 inches, and 4.4 inches:

We can use the following steps to perform a two-way ANOVA:

**Step 1: Calculate Sum of Squares for First Factor (Watering Frequency)**

First, we will calculate the grand mean height of all 40 plants:

Grand mean = (4.8 + 5 + 6.4 + 6.3 + … + 3.9 + 4.8 + 5.5 + 5.5) / 40 = **5.1525**

Next, we will calculate the mean height of all plants watered daily:

Mean of Daily = (4.8 + 5 + 6.4 + 6.3 + … + 4.4 + 4.8 + 5.8 + 5.8) /20 = **5.155**

Next, we will calculate the mean height of all plants watered weekly:

Mean of Weekly = (4.4 + 4.9 + 5.8 + 6 + … + 3.9 + 4.8 + 5.5 + 5.5) /20 = **5.15**

Next, we will calculate the sum of squares for the factor “watering frequency” by using the following formula:

Σn(X_{j} – X..)^{2}

where:

**n**: the sample size of group j**Σ**: a greek symbol that means “sum”**X**: the mean of group j_{j}**X..**: the grand mean

In our example, we calculate the sum of squares for the factor “watering frequency” to be: 20(5.155-5.1525)^{2} + 20(5.15-5.1525)^{2} = **.00025**

**Step 2: Calculate Sum of Squares for Second Factor (Sunlight Exposure)**

First, we will calculate the grand mean height of all 40 plants:

Grand mean = (4.8 + 5 + 6.4 + 6.3 + … + 3.9 + 4.8 + 5.5 + 5.5) / 40 = **5.1525**

Next, we will calculate the mean height of all plants with no sunlight exposure:

Mean of No Sunlight = (4.8 + 4.4 + 3.2 + 3.9 + 4.4 + 4.4 + 4.2 + 3.8 + 3.7 + 3.9) / 10 = **4.07**

We will repeat this calculation to find the mean height of plants with various sunlight exposures:

- Mean of Low Sunlight =
**5.1** - Mean of Medium Sunlight =
**5.89** - Mean of High Sunlight =
**5.55**

Next, we will calculate the sum of squares for the factor “sunlight exposure” by using the following formula:

Σn(X_{j} – X..)^{2}

where:

**n**: the sample size of group j**Σ**: a greek symbol that means “sum”**X**: the mean of group j_{j}**X..**: the grand mean

In our example, we calculate the sum of squares for the factor “sunlight exposure” to be: 10(4.07-5.1525)^{2} + 10(5.1-5.1525)^{2} + 10(5.89-5.1525)^{2} + 10(5.55-5.1525)^{2} = **18.76475**

**Step 3: Calculate Sum of Squares Within (Error)**

Next, we will calculate the sum of squares within by taking the sum of squared differences between each combination of factors and the individual plant heights.

For example, the mean height of all plants watered daily with no sunlight exposure is 4.14. We can then calculate the sum of squared differences for each of these individual plants as:

- SS for daily watering and no sunlight: (4.8-4.14)
^{2}+ (4.4-4.14)^{2}+ (3.2-4.14)^{2}+ (3.9-4.14)^{2}+ (4.4-4.14)^{2}=**1.512**

We can repeat this process for each combination of factors:

- SS for daily watering and low sunlight:
**0.928** - SS for daily watering and medium sunlight:
**1.788** - SS for daily watering and high sunlight:
**1.648** - SS for weekly watering and no sunlight:
**0.34** - SS for weekly watering and low sunlight:
**0.548** - SS for weekly watering and medium sunlight:
**0.652** - SS for weekly watering and high sunlight:
**1.268**

We can then take the sum of all of these values to find the sum of squares within (error):

Sums of squares within = 1.512 + .928 + 1.788 + 1.648 + .34 + .548 + .652 + 1.268 = **8.684**

**Step 4: Calculate Total Sum of Squares**

Next, we can calculate the total sum of squares by taking the sum of the differences between each individual plant height and the grand mean:

Total Sum of Squares = (4.8 – 5.1525)^{2} + (5 – 5.1525)^{2} + … + (5.5 – 5.1525)^{2} = **28.45975**

**Step 5: Calculate Sum of Squares Interaction**

Next, we will calculate the sum of squares interaction by using the following formula:

- SS Interaction = SS Total – SS Factor 1 – SS Factor 2 – SS Within
- SS Interaction = 28.45975 – .00025 – 18.76475 – 8.684
- SS Interaction =
**1.01075**

**Step 6: Fill in ANOVA Table**

Lastly, we’ll fill in the values for the two-way ANOVA table:

Here is how we calculated the various numbers in the table:

**df Watering Frequency:**j-1 = 2-1 = 1**df Sunlight Exposure:**k-1 = 4-1 = 3**df Interaction**: (j-1)*(k-1) = 1*3 = 3**df Within**: n – (j*k) = 40 – (2*4) = 32**df total:**n-1 = 40-1 = 39**MS:**SS/ df**F Watering Frequency**: MS Watering Frequency / MS Within**F Sunlight Exposure**: MS Sunlight Exposure / MS Within**F Interaction**: MS Interaction / MS Within**p-value Watering Frequency**: The p-value that corresponds to F value of .000921 with df numerator = 1 and df denominator = 32**p-value Sunlight Exposure**: The p-value that corresponds to F value of 23.04898 with df numerator = 3 and df denominator = 32**p-value Interaction**: The p-value that corresponds to F value of 1.241517 with df numerator = 3 and df denominator = 32

**Note #1: **n = total observations, j = number of levels for watering frequency, k = number of levels for sunlight exposure.

**Note #2**: The p-values that correspond to the F-value were calculated using the F Distribution Calculator.

**Step 7: Interpret the results**

We can observe the following from the ANOVA table:

- The p-value for the interaction between watering frequency and sunlight exposure was
**0.311**. This is not statistically significant at α = 0.05. - The p-value for watering frequency was
**0.975**. This is not statistically significant at α = 0.05. - The p-value for sunlight exposure was
**< 0.000**. This is statistically significant at α = 0.05.

These results indicate that sunlight exposure is the only factor that has a statistically significant effect on plant height.

And because there is no interaction effect, the effect of sunlight exposure is consistent across each level of watering frequency.

That is, whether a plant is watered daily or weekly has no impact on how sunlight exposure affects a plant.

**Additional Resources**

The following tutorials provide additional information about ANOVA’s:

How to Perform a One-Way ANOVA by Hand

How to Perform a Repeated Measures ANOVA By Hand

The Complete Guide: How to Report Two-Way ANOVA Results