Professional Documents
Culture Documents
Two Way ANOVA Explained
Two Way ANOVA Explained
Two Way ANOVA Explained
We can extend the idea of a one-way ANOVA, which tests the effects of one factor on a
response variable, to a two-way ANOVA which tests the effects of two factors and their
interaction on a response variable. Thus, each experimental unit is classified by two factors; e.g.,
treatment group and sex, forest location and soil groups, type of thinning and site quality class,
etc. Each factor can have different levels; e.g., two levels for sex: male and female, four levels
of thinning prescriptions: low, medium, high, control. The two-way ANOVA tests the null
hypotheses of equal means for each factor, as we will see in the upcoming example.
Sources of Variation: As with the t-test and the one-way ANOVA, we assume that the variances
are homogeneous. In a manner analogous to the one-way ANOVAs within-group sums of
squares, we can calculate a within-cells sums of squares and corresponding degrees of freedom,
which under the assumption of constant variance, can be used to obtain a pooled variance
common to all cells:
2
n
within-cells SS = (X ijl X ij )
i =1 j=1
l=1
a
i =1 j=1
cells DF = ab 1.
Finally, we need to know the variability among all the data, N, which is also analogous to that of
the one-way ANOVA:
(X
a
total SS =
i =1 j=1 l =1
X) ,
2
ijl
total DF = N 1.
In a two-way ANOVA, we typically want to know about the differences between the two factors
when considered independently. Thus, we want to examine the specific components of the cells
SS and cells DF. We can examine these differences by only considering one factor at a time in
the ANOVA. So, for factor A:
SS(A) = bn (X i. X ) ,
a
i =1
DF(A) = a 1,
and for factor B,
SS(B) = an (X . j X ) ,
b
j=1
DF(B) = b 1.
However, the sums of squares and degrees of freedom for factor A and factor B will not exactly
sum to the cells SS because of interaction between the factors. The relationship is additive and it
can be expressed as:
SS(AxB) = SS(Cells) SS(A) SS(B),
DF(A x B) = DF(Cells) DF(A) DF(B) = (a 1)(b 1).
An interaction between the two factors implies that they are not independent of each other. We
will test interaction to determine if it is actually significant in an upcoming example.
As with the one-way ANOVA, you can divide the different SS by their corresponding DF to
obtain a variance, called a mean square:
MS( A ) =
SS( A )
,
DF( A )
MS(B ) =
SS(B )
,
DF(B )
MS( AxB) =
SS( AxB)
,
DF( AxB)
3
SS(Error )
.
DF(Error )
MS(Error ) =
Error MS is usually called the mean square error (MSE). As with the one-way ANOVA, these
ratios are F-distributed. So, we can calculate corresponding F-statistics and compare to a onetailed critical value from the F-distribution for our hypothesis tests (for a Model I ANOVA see
discussion later in the notes):
F=
MS( A )
, for Ho: no effect of factor A on response variable,
MSE
F=
MS(B )
, for Ho: no effect of factor B on response variable,
MSE
F=
MS( AxB)
, for Ho: no interaction between factor A and factor B.
MSE
n (X
a
Cells
i =1 j=1
X)
ij
Degrees of
Freedom (DF)
a1
an (X . j X )
b-1
cells SS factor A SS
factor B SS
(a 1)(b 1)
2
n
(
)
X
X
ijl ij
i =1 j=1
l=1
ab(n 1)
Factor A
i =1
b
Factor B
j=1
AxB
Error
(X
a
Total
i =1 j=1 l =1
X)
ijl
F-statistic
ab - 1
bn (X i. X )
a
SS( A )
DF( A )
SS(B )
DF(B )
SS( AxB)
DF( AxB)
MS( A )
MSE
MS(B )
F=
MSE
F=
F=
MS( AxB)
MSE
SS(Error )
DF(Error )
N1
Ho2: There is no difference in the mean plasma calcium concentration between male and
Ho3: There is no interaction of sex and hormone treatment on the mean plasma calcium
concentration of birds.
Ha3: There is an interaction of sex and hormone treatment on the mean plasma calcium
concentration of birds.
= 0.05.
I used the example SAS program, TwoWayAnova.sas, with the data presented in Zar to
perform the ANOVA. I obtained the following ANOVA table:
Source of
Variation
Cells
Treatment
Gender
Treatment x Gender
Error
Total
Sums of Squares
Degrees of
(SS)
Freedom (DF)
1461.3255
3
1386.1125
1
70.3125
1
4.9005
1
301.3920
16
1762.2175
19
Mean Square
(MS)
F-statistic
p-value
1386.1125
70.3125
4.9005
73.585
3.733
0.260
< 0.0001
0.0713
0.6170
18.8370
As you can see from the table, the F-statistic for the null hypotheses of no interaction (Ho3) is not
significant (p-value = 0.6170 > 0.05). The F-statistic for the null hypothesis of no difference
between sexes (Ho2) is also not significant (p = 0.0713 > 0.05). However, the F-statistic for the
null hypothesis of no treatment effect (Ho1) is highly significant ( p < 0.0001 << 0.05). Thus, we
conclude that hormone treatment affects the plasma calcium concentration in this sample of
birds.
If we had more than two levels in the treatment effect (e.g., two treatments and one control = 3
levels), we could use multiple comparison tests to determine where differences exist between
treatments. The procedure is the same as that for multiple comparisons in a one-way ANOVA.
If both factors are significant and they have more than two levels, we can perform multiple
comparison tests for both factors separately.
Assumptions of ANOVA
The assumptions in the two-way ANOVA are the same as in the t-tests and one-way ANOVA:
homogeneity of variance and normally distributed data. You can test these assumptions using
the procedures we have already discussed. Remember that ANOVA is very robust and can thus
handle all but the most extreme violations of these assumptions. If you are convinced that the
assumptions are violated, you can resort to some non-parametric analogs of two-way ANOVA.
However, many of these non-parametric procedures are not fully developed or widely available
in computer programs.
You should also know that there are three types of two-way (and n-way) ANOVAs:
6
1. Model I or Fixed-effects ANOVA: In this type of two-way ANOVA, the factor levels are
fixed by the experimenter. Thus, the factors are said to be crossed, as we previously
mentioned. The example we just completed is an example of a Model I ANOVA. Note:
This is the same Model I ANOVA we discussed for the one-way ANOVA.
Another thing that differs from the one-way ANOVA is the interaction term. In our
example, we found that the interaction effect was not significant. Thus, we could then
test for individual factor effects. If the interaction had been significant, we could not say
anything meaningful about factor effects because the difference between the levels of one
factor is not constant at all levels of the other factor (see Zars Figure 12.2, page 260).
2. Model II or Random-effects ANOVA: This rare type of two-way ANOVA occurs when
the levels of the factor are selected randomly. The F-statistics are calculated differently
than the Model I ANOVA (see Zars Table 12.3, page 262). Note: This is the same
Model II ANOVA we discussed for the one-way ANOVA.
3. Model III or Mixed-effects ANOVA: This type of factorial design has both a fixed and
random effect factor. The F-statistics are again calculated differently than either the
Model I or Model II ANOVA (see Zars Table 12.3, page 262). For example, if factor A
is fixed and factor B is random, the F-statistics are calculated as:
Factor A (fixed): F =
MS( A )
,
MS( AxB)
Factor B (random): F =
MS(B )
,
MSE
Interaction: F =
MS( AxB)
.
MSE
Source of
Variation
Sums of Squares
(SS)
Treatment (i)
b (X i. X )
Degrees of
Freedom
(DF)
Mean Square
(MS)
a-1
Treatment SS
Treatment DF
i =1
F=
Treatment MS
Re mainder MS
a (X . j X )
b1
Total SS Treatment
SS Block SS
(a 1)(b-1)
Blocks (j)
F-statistic
j=1
Remainder
(X
a
Total
i =1 j=1
X)
ij
Re mainder SS
Re mainder DF
ab 1 = N -1
Example: A researcher is interested in the effect of several herbicides on the spike weight
Block 1
1.25
2.05
1.95
1.75
Block 2
1.73
1.56
2.00
1.93
Block 3
1.82
1.68
1.83
1.70
Block 4
1.31
1.69
1.81
1.59
10
Note: You can perform multiple comparisons/contrasts for the fixed effects factor (i.e.,
treatments) in the same manner as the two-way ANOVA, though it was unnecessary in this case
since we did not reject Ho (see Zar, page 274, Section 12.5).
Friedmans Test
This is the non-parametric analog of the randomized block ANOVA. It is useful when your data
for this design do not meet the assumptions of the parametric ANOVA. Like other nonparametric techniques, the analysis is performed on ranks rather than the original data. To carry
out this test:
1. Rank the treatments within each block.
2. Calculate the rank sums, Ri, for each treatment.
3. Find chi-square statistic: 2r =
a
12
R i2 3b(a + 1) .
ba (a + 1) i 1
4. Compare the chi-square statistic to a critical value from Table B.14 in appendix. If the
critical value is not in the table, compare to a chi-square value with (a 1) degrees of
freedom, which approximates the critical value (though it tends to be conservative more
likely to commit a Type II error see Zar, page 277 to 279, for a suggested solution).
11
Example: Lets continue with the gladiolus example from before. First, rank the data within
Block 1
Block 2
Block 3
Block 4
Rank Sums
15
Test statistic: 2r =
12
(
7 2 + 9 2 + 15 2 + 9 2 ) 3 4(4 + 1) = 5.4 .
4 4(4 + 1)
Decision Rule: If 2r 7.80 (value from Table B.14), then reject Ho; otherwise do not reject Ho.
Conclusion: Since 5.4 < 7.8 (0.1 < P < 0.2), do not reject Ho same conclusion as before.
Note: I also provided an example SAS file (FriedmansTest.sas) on the webpage. Use the second
test statistic, Row Mean Scores Differ, for hypothesis testing. Also, you can perform nonparametric multiple comparisons/contrasts as for the parametric randomized block ANOVA,
though again it was unnecessary since we did not reject Ho (see Zar, page 280). However, SAS
does not provide non-parametric multiple comparisons so you will have to calculate them by
hand/programming.
12