In the previous chapter we used one-way ANOVA to analyze data from three or more populations using the null hypothesis that all means were the same (no treatment effect). For example, a biologist wants to compare mean growth for three different levels of fertilizer. A one-way ANOVA tests to see if at least one of the treatment means is significantly different from the others. If the null hypothesis is rejected, a multiple comparison method, such as Tukey’s, can be used to identify which means are different, and the confidence interval can be used to estimate the difference between the different means. Show
Suppose the biologist wants to ask this same question but with two different species of plants while still testing the three different levels of fertilizer. The biologist needs to investigate not only the average growth between the two species (main effect A) and the average growth for the three levels of fertilizer (main effect B), but also the interaction or relationship between the two factors of species and fertilizer. Two-way analysis of variance allows you to examine the effect of two factors simultaneously on the average response. The interaction of these two factors is always the starting point for two-way ANOVA. If the interaction term is significant, then you will ignore the main effects and focus solely on the unique treatments (combinations of the different levels of the two factors). If the interaction term is not significant, then it is appropriate to investigate the presence of the main effect of the response variable separately. ANOVA (Analysis of Variance) is a statistical test used to analyze the difference between the means of more than two groups. A two-way ANOVA is used to estimate how the mean of a quantitative variable changes according to the levels of two categorical variables. Use a two-way ANOVA when you want to know how two independent variables, in combination, affect a dependent variable. ExampleYou are researching which type of fertilizer and planting density produces the greatest crop yield in a field experiment. You assign different plots in a field to a combination of fertilizer type (1, 2, or 3) and planting density (1=low density, 2=high density), and measure the final crop yield in bushels per acre at harvest time.You can use a two-way ANOVA to find out if fertilizer type and planting density have an effect on average crop yield. Table of contentsWhen to use a two-way ANOVAYou can use a two-way ANOVA when you have collected data on a quantitative dependent variable at multiple levels of two categorical independent variables. A quantitative variable represents amounts or counts of things. It can be divided to find a group mean. Bushels per acre is a quantitative variable because it represents the amount of crop produced. It can be divided to find the average bushels per acre.A categorical variable represents types or categories of things. A level is an individual category within the categorical variable. Fertilizer types 1, 2, and 3 are levels within the categorical variable fertilizer type. Planting densities 1 and 2 are levels within the categorical variable planting density.You should have enough observations in your data set to be able to find the mean of the quantitative dependent variable at each combination of levels of the independent variables. Both of your independent variables should be categorical. If one of your independent variables is categorical and one is quantitative, use an ANCOVA instead. How does the ANOVA test work?ANOVA tests for significance using the F test for statistical significance. The F test is a groupwise comparison test, which means it compares the variance in each group mean to the overall variance in the dependent variable. If the variance within groups is smaller than the variance between groups, the F test will find a higher F value, and therefore a higher likelihood that the difference observed is real and not due to chance. A two-way ANOVA with interaction tests three null hypotheses at the same time:
A two-way ANOVA without interaction (a.k.a. an additive two-way ANOVA) only tests the first two of these hypotheses. Two-way ANOVA hypothesesIn our crop yield experiment, we can test three hypotheses using two-way ANOVA:Null hypothesis (H0)Alternate hypothesis (Ha)There is no difference in average yieldfor any fertilizer type.There is a difference in average yield by fertilizer type.There is no difference in average yield at either planting density.There is a difference in average yield by planting density.The effect of one independent variable on average yield does not depend on the effect of the other independent variable (a.k.a. no interaction effect).There is an interaction effect between planting density and fertilizer type on average yield. Prevent plagiarism, run a free check.Try for freeAssumptions of the two-way ANOVATo use a two-way ANOVA your data should meet certain assumptions.Two-way ANOVA makes all of the normal assumptions of a parametric test of difference:
The variation around the mean for each group being compared should be similar among all groups. If your data don’t meet this assumption, you may be able to use a , like the Kruskal-Wallis test.
Your independent variables should not be dependent on one another (i.e. one should not cause the other). This is impossible to test with categorical variables – it can only be ensured by good experimental design. In addition, your dependent variable should represent unique observations – that is, your observations should not be grouped within locations or individuals. If your data don’t meet this assumption (i.e. if you set up experimental treatments within blocks), you can include a blocking variable and/or use a repeated-measures ANOVA.
The values of the dependent variable should follow a bell curve (they should be normally distributed). If your data don’t meet this assumption, you can try a data transformation. In the crop-yield example, the response variable is normally distributed, and we can after running the model. The experimental treatments were set up within blocks in the field, with four blocks each containing every possible combination of fertilizer type and planting density, so we should include this as a blocking variable in the model.How to perform a two-way ANOVAThe dataset from our imaginary crop yield experiment includes observations of:
The two-way ANOVA will test whether the independent variables (fertilizer type and planting density) have an effect on the dependent variable (average crop yield). But there are some other possible sources of variation in the data that we want to take into account. We applied our experimental treatment in blocks, so we want to know if planting block makes a difference to average crop yield. We also want to check if there is an interaction effect between two independent variables – for example, it’s possible that planting density affects the plants’ ability to take up fertilizer. Because we have a few different possible relationships between our variables, we will compare three models:
Model 1 assumes there is no interaction between the two independent variables. Model 2 assumes that there is an interaction between the two independent variables. Model 3 assumes there is an interaction between the variables, and that the blocking variable is an important source of variation in the data. By running all three versions of the two-way ANOVA with our data and then comparing the models, we can efficiently test which variables, and in which combinations, are important for describing the data, and see whether the planting block matters for average crop yield. This is not the only way to do your analysis, but it is a good method for efficiently comparing models based on what you think are reasonable combinations of variables. Running a two-way ANOVA in RWe will run our analysis in R. To try it yourself, download the sample dataset. Sample dataset for a two-way ANOVA After loading the data into the R environment, we will create each of the three models using the This first model does not predict any interaction between the independent variables, so we put them together with a ‘+’. Two-way ANOVA R codetwo.way <- aov(yield ~ fertilizer + density, data = crop.data) In the second model, to test whether the interaction of fertilizer type and planting density influences the final yield, use a ‘ * ‘ to specify that you also want to know the interaction effect. Two-way ANOVA with interaction R codeinteraction <- aov(yield ~ fertilizer * density, data = crop.data) Because our crop treatments were randomized within blocks, we add this variable as a blocking factor in the third model. We can then compare our two-way ANOVAs with and without the blocking variable to see whether the planting location matters. Two-way ANOVA with blocking R codeblocking <- aov(yield ~ fertilizer * density + block, data = crop.data) Model comparisonNow we can find out which model is the best fit for our data using AIC (Akaike information criterion) model selection. AIC calculates the best-fit model by finding the model that explains the largest amount of variation in the response variable while using the fewest parameters. We can perform a model comparison in R using the
The output looks like this: The AIC model with the best fit will be listed first, with the second-best listed next, and so on. This comparison reveals that the two-way ANOVA without any interaction or blocking effects is the best fit for the data. Interpreting the results of a two-way ANOVAYou can view the summary of the two-way model in R using the summary(two.way) The output looks like this: The model summary first lists the independent variables being tested (‘fertilizer’ and ‘density’). Next is the residual variance (‘Residuals’), which is the variation in the dependent variable that isn’t explained by the independent variables. The following columns provide all of the information needed to interpret the model:
From this output we can see that both fertilizer type and planting density explain a significant amount of variation in average crop yield (p values < 0.001). Post-hoc testingANOVA will tell you which parameters are significant, but not which levels are actually different from one another. To test this we can use a post-hoc test. The Tukey’s Honestly-Significant-Difference (TukeyHSD) test lets us see which groups are different from one another. Tukey R codeTukeyHSD(two.way) The output looks like this: This output shows the pairwise differences between the three types of fertilizer ($fertilizer) and between the two levels of planting density ($density), with the average difference (‘diff’), the lower and upper bounds of the 95% confidence interval (‘lwr’ and ‘upr’) and the p value of the difference (‘p-adj’). From the post-hoc test results, we see that there are significant differences (p < 0.05) between:
but no difference between fertilizer groups 2 and 1. How to present the results of a a two-way ANOVAOnce you have your model output, you can report the results in the results section of your thesis, dissertation or research paper. When reporting the results you should include the F statistic, degrees of freedom, and p value from your model output. Example resultsWe found a statistically-significant difference in average corn yield by both fertilizer type (F(2)=9.018, p < 0.001) and by planting density (F(1)=15.316, p < 0.001), though the interaction between these terms was not significant.A Tukey post-hoc test revealed significant pairwise differences between fertilizer mix 3 and fertilizer mix 1 (+ 0.59 bushels/acre under mix 3), between fertilizer mix 3 and fertilizer mix 2 (+ 0.42 bushels/acre under mix 2), and between planting density 2 and planting density 1 ( + 0.46 bushels/acre under density 2). You can discuss what these findings mean in the discussion section of your paper. Example discussionThe increased production under fertilizer mix 3 and at higher planting densities suggests that under field conditions similar to ours, this combination would be most advantageous for crop yield. The lack of interaction between fertilizer type and planting densities suggests that planting density does not affect the ability of the plants to take up fertilizer, though at densities higher than ours this may become the case.You may also want to of your results to illustrate your findings. Your graph should include the groupwise comparisons tested in the ANOVA, with the raw data points, summary statistics (represented here as means and standard error bars), and letters or significance values above the groups to show which groups are significantly different from the others. Frequently asked questions about two-way ANOVAWhat is the difference between a one-way and a two-way ANOVA? The only difference between one-way and two-way ANOVA is the number of independent variables. A one-way ANOVA has one independent variable, while a two-way ANOVA has two.
All ANOVAs are designed to test for differences among three or more groups. If you are only testing for a difference between two groups, use a t-test instead. How is statistical significance calculated in an ANOVA? In ANOVA, the null hypothesis is that there is no difference among group means. If any group differs significantly from the overall group mean, then the ANOVA will report a statistically significant result. Significant differences among group means are calculated using the F statistic, which is the ratio of the mean sum of squares (the variance explained by the independent variable) to the mean square error (the variance left over). If the F statistic is higher than the critical value (the value of F that corresponds with your alpha value, usually 0.05), then the difference among groups is deemed statistically significant. What is a factorial ANOVA? A factorial ANOVA is any ANOVA that uses more than one categorical independent variable. A two-way ANOVA is a type of factorial ANOVA. Some examples of factorial ANOVAs include:
What is the difference between quantitative and categorical variables? Quantitative variables are any variables where the data represent amounts (e.g. height, weight, or age). Categorical variables are any variables where the data represent groups. This includes rankings (e.g. finishing places in a race), classifications (e.g. brands of cereal), and binary outcomes (e.g. coin flips). You need to know what type of variables you are working with to choose the right statistical test for your data and interpret your results. Cite this Scribbr articleIf you want to cite this source, you can copy and paste the citation or click the “Cite this Scribbr article” button to automatically add the citation to our free Citation Generator.
|