Documentation |
Two-way analysis of variance
p = anova2(X,reps)
p = anova2(X,reps,displayopt)
[p,table] = anova2(...)
[p,table,stats] = anova2(...)
p = anova2(X,reps) performs a balanced two-way ANOVA for comparing the means of two or more columns and two or more rows of the observations in X. The data in different columns represent changes in factor A. The data in different rows represent changes in factor B. If there is more than one observation for each combination of factors, input reps indicates the number of replicates in each position, which must be constant. (For unbalanced designs, use anovan.)
The matrix below shows the format for a set-up where column factor A has two levels, row factor B has three levels, and there are two replications (reps = 2). The subscripts indicate row, column, and replicate, respectively.
$$\begin{array}{c}\begin{array}{cc}A=1& A=2\end{array}\\ \left[\begin{array}{cc}{x}_{111}& {x}_{121}\\ {x}_{112}& {x}_{122}\\ {x}_{211}& {x}_{221}\\ {x}_{212}& {x}_{222}\\ {x}_{311}& {x}_{321}\\ {x}_{312}& {x}_{322}\end{array}\right]\end{array}\begin{array}{c}\\ \begin{array}{c}\begin{array}{c}\\ \end{array}\}B=1\\ \begin{array}{c}\\ \end{array}\}B=2\\ \begin{array}{c}\\ \end{array}\}B=3\end{array}\end{array}$$
When reps is 1 (default), anova2 returns two p-values in vector p:
The p value for the null hypothesis, H_{0A}, that all samples from factor A (i.e., all column-samples in X) are drawn from the same population
The p value for the null hypothesis, H_{0B}, that all samples from factor B (i.e., all row-samples in X) are drawn from the same population
When reps is greater than 1, anova2 returns a third p value in vector p:
The p value for the null hypothesis, H_{0AB}, that the effects due to factors A and B are additive (i.e., that there is no interaction between factors A and B)
If any p value is near zero, this casts doubt on the associated null hypothesis. A sufficiently small p value for H_{0A} suggests that at least one column-sample mean is significantly different that the other column-sample means; i.e., there is a main effect due to factor A. A sufficiently small p value for H_{0B} suggests that at least one row-sample mean is significantly different than the other row-sample means; i.e., there is a main effect due to factor B. A sufficiently small p value for H_{0AB} suggests that there is an interaction between factors A and B. The choice of a limit for the p value to determine whether a result is "statistically significant" is left to the researcher. It is common to declare a result significant if the p value is less than 0.05 or 0.01.
anova2 also displays a figure showing the standard ANOVA table, which divides the variability of the data in X into three or four parts depending on the value of reps:
The variability due to the differences among the column means
The variability due to the differences among the row means
The variability due to the interaction between rows and columns (if reps is greater than its default value of one)
The remaining variability not explained by any systematic source
The ANOVA table has five columns:
The first shows the source of the variability.
The second shows the Sum of Squares (SS) due to each source.
The third shows the degrees of freedom (df) associated with each source.
The fourth shows the Mean Squares (MS), which is the ratio SS/df.
The fifth shows the F statistics, which is the ratio of the mean squares.
p = anova2(X,reps,displayopt) enables the ANOVA table display when displayopt is 'on' (default) and suppresses the display when displayopt is 'off'.
[p,table] = anova2(...) returns the ANOVA table (including column and row labels) in cell array table. (Copy a text version of the ANOVA table to the clipboard by using the Copy Text item on the Edit menu.)
[p,table,stats] = anova2(...) returns a stats structure that you can use to perform a follow-up multiple comparison test.
The anova2 test evaluates the hypothesis that the row, column, and interaction effects are all the same, against the alternative that they are not all the same. Sometimes it is preferable to perform a test to determine which pairs of effects are significantly different, and which are not. Use the multcompare function to perform such tests by supplying the stats structure as input.