This page explains how to perform a two-factor ANOVA and to interpret the results of this test. Some of the text that follows assumes that you already have a basic familiarity with analysis of variance, so if you have not already done so it is recommended that you read the Introduction to ANOVA and One-factor ANOVA pages before proceeding further.
Two-factor ANOVA is used to analyze experimental designs that include two, rather than just one, independent variables. The simplest type of design is one in which each variable has two levels, but it is perfectly possible for one or both variables to have three or more levels, as the example that will be analyzed later illustrates.
Why would you want to carry out an experiment that studies two independent variables simultaneously, rather than doing two separate experiments (each of which could be analyzed with a two-sample t-test or a one-factor ANOVA)? There are two reasons for doing so. The first is because it is more efficient. With the same sample size (and thus with virtually the same statistical power), and with relatively little extra effort and expense, the effects of two variables can be studied rather than just one. This is particularly important when the study units are human subjects, or lab animals that need to be cared for humanely and may have to be sacrificed at the end of the experiment. The second reason is that it enables a researcher to look for interactions between the independent variables.
Consider a hypothetical study of the effects of two diet types (D1 and D2) and two pharmaceuticals (P1 and P2) on blood cholesterol concentration (BCC). An experiment that includes all four possible treatment combinations (D1 and P1; D1 and P2; D2 and P1; D2 and P2), with patients assigned at random to one of the four groups is called a factorial design and allows the investigation of three different questions:
- Is BCC influenced by diet type?
- Is BCC influenced by pharmaceutical type?
- Is the effect of pharmaceutical type on BCC influenced by diet?
Diet type and pharmaceutical type are referred to as main effects, and each of them alone might have an effect on BCC (Questions 1 and 2). There might also be an interaction effect, in which the effect of pharmaceutical type is influenced by diet (Question 3).
The presence or absence of an interaction effect in factorial designs can be illustrated graphically with reference to some possible outcomes of the above experiment. One possibility is illustrated below:
In this example, patients taking pharmaceutical P2 had a lower BCC than those taking P1 (averaged across the two diets), and those on diet D2 had a lower BCC than those on D1 (averaged across the two pharmaceuticals). Thus, both diet and pharmaceutical type affect BCC. However, the magnitude of the difference in BCC between the two pharmaceuticals was approximately the same (40 units) regardless of diet. Thus, the effect of pharmaceutical type is independent of diet and there is no interaction between the two variables.
Now consider a second possible experimental outcome:
In this example, patients taking pharmaceutical P2 had a lower BCC when on diet D1, but a higher BCC when on diet D2. Thus, the effect of pharmaceutical type depends on diet, and there is an interaction between the two variables. When the effect of one variable (in this case pharmaceutical type) reverses across the two levels of the second (in this case diet), the pattern is described as a crossing interaction (because lines joining the two means for each pharmaceutical would cross one another in the figure).
Finally, consider a third possible experimental outcome:
In this example, patients taking pharmaceutical P2 had a lower BCC when on diet D1, but there was no difference between the two pharmaceuticals when patients were on diet D2. Again, the effect of pharmaceutical type depends on diet, and there is an interaction between the two variables. However, in contrast to the previous example, the effect of pharmaceutical type does not reverse across the two diets, and the pattern is described as a non-crossing interaction (because lines joining the two means for each pharmaceutical would not cross one another in the figure).
Two-factor ANOVA will be illustrated using the same data on oak seedling photosynthetic rates that was used to illustrate one-factor ANOVA. If you are not already familiar with one-factor ANOVA, it is recommended that you read that page first.
First, import the data in the Excel spreadsheet below into JMP.
After the import, Ecotype should be coded as a categorical variable (as indicated by the red histogram in the column list on the left); all the other variables should be coded as continuous (as indicated by the blue triangles). However, before starting the analysis it is necessary to recode both the Transect and Plant # variables. On the Excel spreadsheet both were entered as numbers, so JMP interpreted them as continuous variables. However, in reality both are categorical: the numbers are just an identification code and could just as easily have been letters. For each variable in turn, double click on the variable name box at the top of the column and in the pop-up window change Data Type to Character (the Modeling Type will automatically change to Nominal), then hit OK. The symbol next to the variable in the column list should then change to a red histogram.
When these data were analyzed using one-factor ANOVA, the question of interest was whether photosynthetic rate was affected by the elevation of the four transects on the sandy ridge where the seedlings had been planted. However, the researchers were also interested in whether photosynthetic rate was affected by the ecotype of the seedlings. Ecotypes are genetically different populations of a species that are adapted to their local ecological conditions. In this study, half the seedlings had been grown from acorns collected near the Twin Cities and half from acorns collected near Des Moines, Iowa. If the oak trees in these two locations were genetically adapted to their local environments, their photosynthetic physiology might be different, and this might result in their offspring having different photosynthetic rates when planted in a common environment. There might also be an interaction between the two independent variables (transect elevation and seedling ecotype). For example, photosynthetic rates might be similar at lower elevations where water is relatively abundant, but Twin Cities seedlings might have higher photosynthetic rates at higher elevations where water is scarcer (if Twin Cities oak trees are adapted to thrive in the relatively drier summer conditions typically experienced in our region compared to Des Moines).
Thus, three null hypotheses can be tested with this data set:
- There is no difference in mean photosynthetic rate between the two ecotypes (main effect 1).
- There are no differences in mean photosynthetic rate among the four groups of seedlings planted along each of the four transects (main effect 2).
- The effect of ecotype on photosynthetic rate does not depend on transect elevation (interaction effect).
The analysis can be performed in JMP as follows:
- From the Analyze menu select Fit Model and click or drag Sqrt Photosynthetic Rate into the Y box and both Ecotype and Transect (in that order) into the Construct Model Effects box. (Sqrt Photosynthetic Rate is a transformed variable – the square root of the actual photosynthetic rate. The transformation was carried out because the Photosynthetic Rate variable was not normally distributed, whereas its square root was. See Foundational Material for more detail on data transformations.)
- To add the interaction effect into the analysis, highlight Ecotype in the Construct Model Effects box and Transect in the Columns box and then click on Cross. The interaction effect (Ecotype*Transect) will now appear in the Construct Model Effects box.
- Hit Run
- As with the one-factor ANOVA analysed using Fit Model, the output window will show a series of figures as well as several summary tables. Most of these have uses beyond the scope of this website. Close the Residual by Predicted Plot and the Effect Summary and Parameter Estimates tables by clicking on their grey arrows. You can also close the three Leverage Plots by clicking on their grey arrows too.
- Click on the red arrow next to Ecotype and select LS Means Plot. Do the same for the red arrows next to Transect and Ecotype*Transect. The window will now look like this.
Click here to download a high-resolution image of this window SW Oaks Two Factor Output download.
As with one-factor ANOVA, the most important pieces of information in this window are as follows:
- In the Summary of Fit table the R2 value (RSquare = 0.1799) tells us that approximately 18% of the total variation in the dependent variable (square root photosynthetic rate) can be explained by the three effects under consideration: the two main effects (Ecotype and Transect) and their interaction. The total sample size is also given (108).
- The Analysis of Variance table gives the group mean square for all three effects together (the Model row) and the error mean square (the Error row), the ratio of the two (F Ratio) and the associated p-value (Prob > F = 0.0049). Since the p-value is well below the normal threshold for statistical significance (0.05), we can conclude that the three effects together do have a significant effect on photosynthetic rate. However, this information alone does not tell us which of the three individual effects are responsible for the overall significance of the test.
- More usefully, the Effect Tests table shows the degrees of freedom (DF), F Ratio, and p-value (Prob > F) for each of the three effects individually. Here we can see that the Transect effect is significant (p = 0.0009) whereas the Ecotype effect (p = 0.2474) is not. The interaction effect (Ecotype*Transect) is also not significant (p = 0.7457). Thus, we can accept null hypotheses 1 and 3 above, but must reject null hypothesis 2 and accept the alternative hypothesis that mean photosynthetic rate does differ among the four groups of seedlings planted on different transects: the same conclusion we reached when the data were analysed using a one-factor ANOVA.
- The Least Squares Means Tables for the main effects (Ecotype and Transect) show two versions of the mean values for each group: the arithmetic mean (Mean column) and the least squares mean (Least Sq Mean column), along with the standard error of the least squares mean. The least squares mean is a mean value for each group that takes into account the effects of other variables in the analysis and controls for differences in sample size among the groups of these other variables. Note that the two means are not the same. If you were to report mean values for the main effects of a two-factor ANOVA in a paper, you would normally report least squares means, not arithmetic means.
- The Least Squares Means Table for the interaction shows the least squares means but not the arithmetic means. This is because the two means have the same value when calculated individually for each of the eight sub-group of data (Twin Cities seedlings in Transect 1, Des Moines seedlings in Transect 1, etc.)
- The three LS Means Plots show the least squares means for the groups of each main effect and the eight subgroups for the interaction effect. The main effects plots also show the standard errors for each group. Although these plots all show some small differences in mean values, the analysis tables described above indicate that only the differences among transect groups are statistically significant.
As with one-factor ANOVA, for the one effect that is statistically significant (Transect) we can ask which of the four groups differ significantly from each other using the Tukey-Kramer HSD test.
- Click on the red arrow next to Transect and select LS Means Tukey HSD. The output will appear below the LS Means Plot.
- Click on the red arrow next to LSMeans Differences Tukey HSD, unselect Crosstab Report and select Ordered Differences Report.
- The additional analyses will now look like this.
- The upper table (called a Connecting Letters Report) shows the least squares means for each of the four transects with a set of letters to the left. Means sharing the same letter do not differ significantly from one another (p > 0.05).
- The lower table (called an Ordered Differences Report) provides more information for each pairwise comparison. The most useful additional information in this table is the p-Value column. This shows, for example, that the mean values for transects 1 and 4 (top row) are significantly different from each other (p = 0.0010), whereas the mean values for transects 1 and 3 are not (p = 0.1996).