Two-Way ANOVA

ANOVA2.83p
ANOVA2.86p
anova2.89p

Assume again that we have r normally distributed populations (the row factors) each having the same variance. Suppose now that c measurements are taken at random from each of r populations and that this procedure is repeated n times (the column factors or trials). We then obtain n random samples of size c from each population for a total of N = c*r*n measurements.

We can again test the hypothesis that the population means are identical. Moreover, we can test whether or not the means from each trial are identical. In this case, we interpret the results as saying whether or not the measurements are independent of population and/or independent of trial. The technique used to analyze this data is called Two-Way Analysis Of Variance.



One Observation Per Cell


When there is only c = 1 measurement per cell, then we assume the data to be given as below:

Trial 1
Trial 2
. . .
Trial n
Pop. 1
x1,1
x1,2
. . .
x1,n
Pop. 2
x2,1
x2,2
. . .
x2,n
.
.
.
. . .
.
.
.
.
. . .
.
Pop. r
xr,1
xr,2
. . .
xr,n


We let M denote the overall mean of the entire sample, and let M[i] denote the sample mean of the ith population (row). The sample mean of the jth trial (column) will be denoted by T[j].

We next define three types of sum of squares. The first is equivalent to SST from one-way ANOVA and measures the error due to difference of population means. It is denoted here by SSA and is given by

SSA = n*c*Sum[ (M[i] - M)^2 , {i, 1, r} ].


The second measures the error due to difference in trial means and is given by

SSB = r*c*Sum[ (T[j] - M)^2 , {j, 1, n} ].


Lastly, we define SSE by

SSE = c*Sum [ Sum[ (xi,j + M - M[i] - T[j])^2 , {j, 1, n} ] , {i, 1, r} ].


We now obtain two test statistics. To test whether the measurements are independent of population, we use the test statistic

x = (n - 1)*SSA / SSE ,

which follows an F-distribution X with r - 1 and (r - 1)(n - 1) degrees of freedom. We reject independence of population if P(X >= x) < a, where a is the level of significance. Thus, we are rejecting the hypothesis that the populations have identical means and concluding that the mean is dependent on the population.


To test whether the measurements are independent of trial, we use the test statistic

y = (r - 1)*SSB / SSE ,

which follows an F-distribution Y with n - 1 and (r - 1)(n - 1) degrees of freedom. We reject independence of trial if P(Y >= y) < a. In that case, we would conclude that the trials have different means.



Using the ANOVA2 Program

The ANOVA2 program can be used to perform this two-way ANOVA test. To execute the program, we first must enter the data into the matrix A in the MATRX menu. We then enter the number of rows, the number of columns, and common number of observations per cell. The program displays the f-statistic and p-value for both tests.



Example 1. A taxi service is measuring how long it takes certain drivers to take a fare from the airport to a particular downtown hotel. The times in minutes of four drivers measured over a week are given below:

Mon
Tue
Wed
Thu
Fri
Sat
Sun
Cab 1
27
31
27
29
33
32
28
Cab 2
25
28
23
30
30
32
26
Cab 3
30
30
26
30
34
33
24
Cab 4
26
32
25
29
33
31
25

We wish to determine if the average time depends on the driver (i.e., population or row) based on these seven sample measurements for each of the four drivers. Then we wish to determine if the average time depends on the day (i.e., trial or column) based on these four sample measuremants for each day. Assuming the times for cabs and days are normally distributed with the same variance, use two-way ANOVA with a 0.05 level of significance to perform both tests.


Solution. We first enter our data into matrix [A] where the number of rows equals the number of populations r and the number of columns equals the number of trials n. In this case, the dimensions are 4 x 7.

On the TI-83: Press MATRX, scroll right to EDIT, press ENTER to edit matrix [A]. Enter the dimensions as 4 by 7. Then enter the data exactly as it appears in the matrix above. For row 1, press 27, press ENTER, press 31, press ENTER, etc. Continue until all data points have been entered into the 4x7 matrix.

On the TI-86: Press MATRX (2nd 7), then F2 (for EDIT), then A (LOG) to edit matrix A. Enter the dimensions as 4 x 7, then enter the data.

On the TI-89: First delete the variable a from the VAR-LINK menu. Then press APPS, then 6, then 3. For Type, scroll right, then down for Matrix. Name the variable a, then enter the Row dimension as 4 and the Col dimension as 7. Then enter the data in the 4x7 matrix screen that appears.


Next, call up the ANOVA2 program. Enter 4 for NO. OF ROWS, and enter 7 for NO. OF COL.. In this example, enter 1 for NO. PER CELL.

For the first test, we receive an f-stat of 2.743 and a row p-value of 0.0733 which is larger than our desired level of significance. Thus, we we do not have significant evidence to reject the hypothesis that the average time is independent of driver (population).

For the second test, we receive an f-stat of 17.2709 and a column p-value of 0.0000014 which is lower than our desired level of significance. Thus we reject that the average time is independent of the day (trial). That is, the average time depends on the day.


Other Feature: On the TI-83: Press STAT, press ENTER. List L1 enumerates the rows 1, 2, 3, 4, and list L2 contains the individual sample means for each of these four populations. List L3 enunerates the columns 1 through 7, and list L4 contains the individual sample means for each of these seven days. The list L5 contains the overall mean, followed by the values of SSA, SSB, and SSE.

On the TI-86: Press LIST (2nd -), then F4. The row means are under yStat, and the column means are under L1. List L2 contains the overall mean, followed by the values of SSA, SSB, and SSE. (You may need to add lists L1 and L2 in the headers next to fStat in order to see them.)

On the TI-89: Press APPS, then 6, then 1. The row means are under c2, and the column means are under c4. Column c5 contains the overall mean, followed by the values of SSA, SSB, and SSE.


If we observe the row sample means 29.571, 27.714, 29.571, and 28.714, it does seem possible that the true means for each driver could be identical, and indeed we have not rejected independence of population. From observing the column means 27, 30.25, 25.25, 29.5, 32.5, 32, 25.75, it does not seem as likely that the true means for each day will be equal, and we have rejected independence of trial.

If the drivers had the same mean, there would still be a 7.33% chance of the row sample means varying as they do with just seven sample points each; while if the days had the same mean, then there would be almost no chance of the column means varying as they do even with just four sample points each.



c Observations Per Cell

When we have c > 1 observations per trial for each population, then we also can test a third null hypothesis of there being no interaction per cell.

Now we assume that the data is given as follows:

Trial 1
Trial 2
. . .
Trial n
Pop. 1
y1,1
y1,2
. . .
y1,n
Pop. 2
y2,1
y2,2
. . .
y2,n
.
.
.
. . .
.
.
.
.
. . .
.
Pop. r
yr,1
yr,2
. . .
yr,n

where yi,j is the averagemeasurement per cell.


We also assume that we have another matrix {Si,j} that gives the sample deviations of the measurements in each cell.


We again define SSA and SSB as above. But now we define SS(AB) by

SS(AB) = c*Sum [ Sum[ (yi,j + M - M[i] - T[j])^2 , {j, 1, n} ] , {i, 1, r} ],

and we define SSE by

SSE = (c -1)*Sum [ Sum[ (Si,j)^2 , {j, 1, n} ] , {i, 1, r} ].


We now obtain three test statistics. To test whether the measurements are independent of population (row), we use the test statistic

x = [SSA / (r -1)] / [SSE / (r*n*(c - 1))] ,

which follows an F-distribution with r - 1 and r*n*(c - 1) degrees of freedom.


To test whether the measurements are independent of trial (column), we use the test statistic

x = [SSB / (n -1)] / [SSE / (r*n(c - 1))] ,

which follows an F-distribution with n - 1 and r*n*(c - 1) degrees of freedom.


To test the hypothesis that there is no interaction per cell, we use the test statistic

x = [SS(AB) / (r - 1)(n -1)] / [SSE / (r*n(c - 1))] ,

which follows an F-distribution with (r - 1)(n - 1) and r*n*(c - 1) degrees of freedom.



Example 2. A researcher is studying how food consumption by rats is affected by a particular drug. There are two row attributes: drug and placebo. There are four types of rat M (male), C (castrated), F (female), and 0 (ovariectomized), thereby creating 8 cells. There will be 5 specimens per cell. The amount of food consumed in grams per 24 hours is listed below:

With a 5 percent level of significance, test the following three null hypotheses: (a) the average food consumed is the same for drug and placebo; (b) the average food consumed is the same for all four types of rat; (c) the interaction is 0 for each cell.

M
C
F
O
Drug
22.56
16.54
18.58
18.20
25.02
24.64
15.44
14.56
23.66
24.62
16.12
15.54
17.22
19.06
16.88
16.82
22.58
20.12
17.58
14.56
Placebo
25.64
22.50
17.82
19.74
28.84
24.48
15.76
17.48
26.00
25.52
12.96
16.46
26.02
24.76
15.00
16.44
23.24
20.62
19.54
15.70


Solution. We first compute the matrices of average values and sample deviations per cell:

Means
M
C
F
O

Drug

22.208
20.996
16.92
15.936

Placebo

25.948
23.576
16.216
17.164

Deviations
M
C
F
O

Drug

2.96471246
3.56312784
1.22711
1.5692928

Placebo

1.98744
1.99335897
2.54508939
1.573111566


Nex,t enter these values into matrices A and B (use a and b on the TI-89). Then execute the ANOVA2 program with 2 rows, 4 columns, and 5 for NO. PER CELL.

We receive a row p-value of 0.02498 from an f-stat of 5.5328. We receive a column p-value of essentially 0 (3E-9) from an f-stat of 28.6451. And we receive an interaction p-value of 0.182 from an f-stat of 1.7226.

Therefore, we reject the hypothesis that the drug and placebo have the same average food consumption (the sample means are 19.015 for drug and 20.726 for placebo); we reject the hypothesis that each type of rat has the same average food consumption (the sample means are 24.078, 22.286, 16.568, and 16.55); but we do not reject the hypothesis that there is no interaction in any cell.



Exercises

1. Three laboratories conduct tests on the cholesterol contents of different brands of the same type of food. Assuming the levels are normally distributed with a common variance, use Two-Way Anova, at the 0.05 level of significance, to test whether the results are independent of laboratory and/or independent of brand.

Brand A
Brand B
Brand C
Brand D
Lab 1
3.2
3.1
3.3
3.0
Lab 2
2.6
2.6
2.8
2.7
Lab 3
3.4
3.2
3.3
3.1


2. An engineer is studying the effects of temperature and time cycles in a dyeing process which measure the brightness of a synthetic fabric on a 50-point scale. Three measurements were taken for each temperature/time cell:

350 deg
375 deg
400 deg
40 cycles
38
37
36
32
35
39
30
40
43
50 cycles
40
39
39
45
42
48
36
46
47

With a 5 percent level of significance, test the following three null hypotheses: (a) the average brightness level is the same for both time cycles; (b) the average brightness level is the same for all three temperatures; (c) the interaction is 0 for each temperature/time cell.



Solutions

1. After entering the data into a 3 x 4 matrix A and executing the ANOVA2 program, we receive a row p-value of about 0.00026 from an f-stat of 43.8387, and a column p-value of 0.12126 from an f-stat of 2.9355. At a 0.05 level of significance, we can say that the measurements depend on the lab (population) but not on the brand (trial).

If the labs had the same mean, then there would be only a 0.00026 probability of the row sample means varying by as much as they do (3.15, 2.675, and 3.25), which gives us evidence to reject. But if the brands had the same mean, there would still be a 12.13% chance of the column sample means varying as they do (3.0667, 2.9667, 3.1333, and 2.9333), which is not strong enough evidence to reject.


2. After computing the sample means and sample deviations for each cell and entering these values into matrices A and B (a and b on the TI-89), we execute the ANOVA2 program with 2 rows, 3 columns, and 3 for No. Per Cell.

We receive a row p-value of 0.008968 from an f-stat of 9.6918. We receive a column p-value of 0.11486 from an f-stat of 2.6057. And we receive an interaction p-value of 0.89575 from an f-stat of 0.1111.

Therefore, we reject the hypothesis that the time cycles have the same average brightness level (the sample means are 36.667 and 42.444); we do not reject the hypothesis that each temperature has the same brightness level (the sample means are 36.833, 39.833, and 42); and we do not reject the hypothesis that there is no interaction in any cell.



Return to Table of Contents.