Published on March 20, 2020 by Rebecca Bevans. Revised on October 3, 2022. 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. You can use a two-way ANOVA to find out if fertilizer type and planting density have an effect on average crop yield. You 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. A categorical variable represents types or categories of things. A level is an individual category within the categorical variable. 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. 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. To 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 non-parametric alternative, 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. 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 check for homoscedasticity 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. blocking <- 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 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 make a graph 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. Sources in this articleWe strongly encourage students to use sources in their work. You can cite our article (APA Style) or take a deep dive into the articles below. This Scribbr article
Is this article helpful?You have already voted. Thanks :-) Your vote is saved :-) Processing your vote... What is the term for an analysis of data that reveals a difference?Analysis of Variance (ANOVA) is a statistical formula used to compare variances across the means (or average) of different groups. A range of scenarios use it to determine if there is any difference between the means of different groups.
What does a 2 way ANOVA tell you?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.
What is a simple analysis of variance also called?simple analysis of variance. Also called one-way anova. See Analysis of variance. factorial design. A research design used to explore more than one treatment variable.
What type of analysis is factorial ANOVA?Factorial analysis of variance (ANOVA) is a statistical procedure that allows researchers to explore the influence of two or more independent variables (factors) on a single dependent variable.
|