Anova
Anova
Note: Much of the math here is tedious but straightforward. Well skim over it in class but you
should be sure to ask questions if you dont understand it.
I.
Overview
A.
We have previously compared two populations, testing hypotheses of the form
H0:
HA:
1 = 2
1 2
when
T You have a dependent, interval level variable
T You have 2 or more populations, i.e. the independent variable is categorical. In
the 2 population case, ANOVA becomes equivalent to a 2-tailed T test (2 sample tests, Case II,
's unknown but assumed equal).
D.
1 = 2 = 3 = ... = J
The means are not all equal.
E.
Simple 1-factor model: Suppose we want to compare the means of J different
populations. We have j samples of size Nj. Any individual score can be written as follows:
yij = + j + ij, where j = 1, J (# groups) and i = 1, 2, ..., Nj
That is, an observation is the sum of three components:
1.
The grand mean of the combined populations. For example, the overall
average income might be $15,000.
2.
A treatment effect j associated with the particular population from which
the observation is taken; put another way, j is the deviation of the group mean from the overall
mean. For example, suppose the average White income is $20,000. Then whites = $5,000.
3.
A random error term ij. This reflects variability within each population.
Not everyone in the group will have the same value. For example, the average white income
might be $20,000, but some whites will make more, some will make less. (For a white who
makes $18,000, ij = -2,000.)
F.
G.
1 = 2 = 3 = ... = J
But if the J means are equal, this means that j = , which means that there are no
treatment effects. That is, the above hypothesis is equivalent to
H0:
1 = 2 = 3 = ... = J = 0
H.
Estimating the treatment effects: As usual, we use sample information to
estimate the population parameters. It is pretty simple to estimate the treatment effects:
J
= y =
Nj
y ij
j = 1 i= 1
Nj
j = y j =
y
i= 1
Nj
ij
T Aj
j = j
- = y - y
j
Nj
Example:
A firm wishes to compare four programs for training workers to perform a certain
manual task. Twenty new employees are randomly assigned to the training programs, with 5 in
each program. At the end of the training period, a test is conducted to see how quickly trainees
can perform the task. The number of times the task is performed per minute is recorded for each
trainee, with the following results:
Observation
Program 1
Program 2
Program 3
Program 4
10
12
12
14
14
11
11
11
13
13
10
11
TAj = yij
59
44
61
43
j = TAj/Nj
11.8
8.8
12.2
8.6
2
total
= s2 =
( y ij - y )2
N -1
SS Total
= MS Total
DF Total
where SS = Sum of squares (i.e. sum of the squared deviations from the mean), DF = degrees of
freedom, and MS = Mean square. Also,
SS Total = SS Within + SS Between
Where
( y ij - y j )2 = ij2 = SS Within = SS Errors = SS Residual
( y
j
y )2 = 2j = N j 2j = SS Between = SS Explained
j
SS Within captures variability within each group. If all group members had the same score, SS
Within would equal 0. It is also called SS Errors or SS Residual, because it reflects variability
that cannot be explained by group membership. Note that there are Nj degrees of freedom
associated with each individual sample, so the total number of degrees of freedom within = (Nj
- 1) = N - J.
SS Between captures variability between each group. If all groups had the same mean, SS
Between would equal 0. The term SS Explained is also used because it reflects variability that is
explained by group membership. Note that there are J samples, one grand mean, hence DF
Between = J - 1.
We further define
MS Within =
MS Between =
MS Total =
SS Within SS Within
=
,
DF Within
N-J
SS Between SS Between
=
,
DF Between
J -1
y ij = y ij - y j + y j , and
y ij - y = y ij - y j + y j - y
We simply add and subtract y j. Why do we do this? Note that yij y j = deviation of the
individual's score from the group score = ij ; and y j y = deviation of the group score from the
total score = j . Hence,
SS Total = ( y ij y ) = ( y ij y j + y j y ) = ( ij + j ) = ij2 + 2j + 2 ij j
2
SS Within captures variability within each group. If all group members had the same score, SS
Within would equal 0. It is also called SS Errors or SS Residual, because it reflects variability
that cannot be explained by group membership. Note that there are Nj degrees of freedom
associated with each individual sample, so the total number of degrees of freedom within = (Nj
- 1) = N - J.
( y
j
y )2 = 2j = N j 2j = SS Between = SS Explained
j
(The third equation is valid because all cases within a group have the same value for y j.) SS
Between captures variability between each group. If all groups had the same mean, SS Between
would equal 0. The term SS Explained is also used because it reflects variability that is
explained by group membership. Note that there are J samples, one grand mean, hence DF
Between = J - 1.
2 ( y ij y j )( y j y ) = 2 ij j = 2 j ij = 2 j * 0 = 0
j
(The latter is true because the deviations from the mean must sum to 0). Hence,
SS Total = SS Within + SS Between
J.
Now that we have these, what do we do with them? For hypothesis testing,
we have to make certain assumptions. Recall that yij = + j + ij. ij is referred to as a "random
error term" or "disturbance." If we assume:
(1) ij - N(0, 2),
(2) 2 is the same for all samples,
(3) the random error terms are independent (Note that these assumptions basically
mean that the 's are iid, independent and identically distributed);
Then, if H0 is true,
F=
MS Between
~ F(J - 1, N - J), and E(F) = 1
MS Within
That is, if H0 is true, then the test statistic F has an F distribution with J - 1 and N - J degrees of
Freedom.
See Appendix E, Table V (Hayes, pp. 935-941), for tables on the F distribution. See especially
tables 5-3 (Q = .05) and 5-5 (Q = .01).
K.
Rationale:
T The basic idea is to determine whether all of the variation in a set of data is
attributable to random error (chance) or whether some of the variation is attributable to chance
and some is attributable to differences in the means of the J populations of interest.
T First, the sample variance for the entire set of data is computed and is seen to
be composed of two parts: the numerator, which is a sum of squares, and the denominator, which
is the degrees of freedom.
T The total sum of squares can be partitioned into SS Between and SS Within,
and the total degrees of freedom can be partitioned into d.f. between and d.f. Within.
T By dividing each sum of squares by the respective d.f., MS between and MS
within are determined; these represent the sample variability between the different samples and
the sample variability within all the samples, respectively.
T But the variability within the samples must be due to random error alone,
according to the assumptions of the one-factor model.
T The variability between the samples, on the other hand, may be attributable
both to chance and to any differences in the J population means.
T Thus, if MS Between is significantly greater than MS Within (as measured by
the F-test), then the null hypothesis of zero treatment effects must be rejected.
L.
T In the tables, columns give the d.f. for MS Between (J - 1), while the rows give
the d.f. for MS Within (N - J).
T Look at Table 5-3, column 1; compare with Table 3 for the T distribution, the
column labeled 2Q = .05. Note that F = T2. A two sample test, case II, 1 = 2 = , with a 2tailed alternative hypothesis, can also be tested using ANOVA.
M.
Computational procedures for ANOVA. The above formulas are, in practice, a
little awkward to deal with. When doing computations by hand, the following procedure is
generally easier:
One Way Anova: Computational Procedures
Formula
Explanation
TAj = the sum of the scores in group Aj, where A1 = first
group, A2 = second group, etc. Add up the values for the
observations for group A1, then A2, etc. Also sometimes
called just Tj.
Nj
T A j = y ij
i
(1) =
( y ij )2
N
= NY
(2) = y ij2
(3) =
T Aj
N Aj
N
j
MS Total = SS Total / (N - 1)
MS Between = SS Between / (J - 1)
MS Within = SS Within / (N - J)
F = MS Between / MS Within
N.
The ANOVA Table. The results of an analysis of variance are often presented in
a table that looks something like the following (with the appropriate values filled in):
Source
SS
D.F.
Mean Square
A (or Treatment, or
Explained)
SS Between
J-1
SS Between/ (J - 1)
MS Between
MS Within
SS Within
N-J
SS Within / (N - J)
Total
SS Total
N-1
SS Total / (N - 1)
O.
Hypothesis testing using ANOVA. As usual, we determine the critical value of
the test statistic for a given value of . If the test statistic is less than the critical value, we accept
H0, if it is greater than the critical value we reject H0.
EXAMPLES:
Again consider this problem: A firm wishes to compare four programs for
1.
training workers to perform a certain manual task. Twenty new employees are randomly
assigned to the training programs, with 5 in each program. At the end of the training period, a
test is conducted to see how quickly trainees can perform the task. The number of times the task
is performed per minute is recorded for each trainee, with the following results:
Program 1:
Program 2:
Program 3:
Program 4:
(a)
(b)
Solution.
(a) As we saw before, TA1 = 59, TA2 = 44, TA3 = 61, TA4 = 43. Also,
(1) =
( y ij )2
N
= 207 = 2142.45
20
T Aj
= 59 + 44 + 61 + 43 = 2197.4
5
5
5
5
N Aj
SS
D.F.
Mean Square
A (or Treatment, or
Explained)
SS Between =
54.95
J-1=
3
SS Between/ (J - 1)
= 18.32
MS Between =
MS Within
SS Within =
41.6
N-J=
16
SS Within / (N - J) =
2.6
7.04
Total
SS Total =
96.55
N-1=
19
SS Total / (N - 1) =
5.08
NOTE: Most computer programs would not be nice enough to spell out "SS Between =", etc.;
that is, you would have to know from the location of the number in the table whether it was SS
Between, MS Within, or whatever. See the SPSS examples below.
(b) For = .05, the critical value for an F with d.f. (3, 16) is 3.24. Ergo, we reject the null
hypothesis. More formally,
Step 1:
H0:
HA:
Step 2:An F statistic is appropriate, since the dependent variable is continuous and there are 2 or
more groups.
Step 3: Since = .05 and d.f. = 3, 16, accept H0 if F3,16 # 3.24
Step 4:The computed value of the F statistic is 7.04
Step 5: Reject H0. The treatments are not equally effective.
There are several SPSS routines that can do one-way Anova. These include ANOVA (which,
alas, requires that you enter the syntax directly rather than use menus; but it will give you the
MCA table if you want it), MEANS, and ONEWAY. Which you use depends on any additional
information you might like as well as the format you happen to like best. Ill use ONEWAY but
feel free to try the others. If using the SPSS pull-down menus, after entering the data select
ANALYZE/ COMPARE MEANS/ ONE WAY ANOVA.
* Problem 1.
Employee training.
N
1.00
2.00
3.00
4.00
Total
5
5
5
5
20
Mean
11.8000
8.8000
12.2000
8.6000
10.3500
Std. Deviation
1.9235
1.6432
1.3038
1.5166
2.2542
Std. Error
.8602
.7348
.5831
.6782
.5041
Minimum
9.00
6.00
11.00
7.00
6.00
Maximum
14.00
10.00
14.00
11.00
14.00
ANOVA
SCORE
Between Groups
Within Groups
Total
2.
Sum of
Squares
54.950
41.600
96.550
df
3
16
19
Mean Square
18.317
2.600
F
7.045
Sig.
.003
a.
A researcher has collected data from 21 Catholics, 21 Protestants, and 21 Jews.
She wants to see whether the groups significantly differ at the .05 level in their incomes. Her
computed F = 3.0.
Solution. Note that n = 63, j = 3. Hence, d.f. = 3 - 1, 63 - 3 = 2, 60. Looking at table V, we see
that for = .05 we should accept H0 if F # 3.15. Since the researcher got an F of 3.0, she should
accept H0.
b.
A manager wants to test (using = .025) whether the mean delivery time of
components supplied by 5 outside contractors is the same. He draws a random sample of 5
delivery times for each of the 5 contractors. He computes the following:
SS Between = 4
SS Within = 50
Solution. Note that n = 25 (5 delivery times for each of 5 contractors) and J = 5 (5 contractors).
Hence
3.
An economist wants to test whether mean housing prices are the same regardless of
which of 3 air-pollution levels typically prevails. A random sample of house purchases in 3
areas yields the price data below.
MEAN HOUSING PRICES (THOUSANDS OF DOLLARS):
Pollution Level
Observation
Low
Mod
High
120
61
40
68
59
55
40
110
73
95
75
45
83
80
64
406
385
277
(a)
(b)
(c)
pollution.
Solution.
(a)
(b)
( y ij )2
N
= 1068 = 76041.6
15
T Aj
SS
D.F.
Mean Square
A (or Treatment, or
Explained)
SS Between =
1916.4
J-1=
2
SS Between/ (J - 1)
= 958.2
MS Between =
MS Within
SS Within =
5982.0
N-J=
12
SS Within / (N - J) =
498.5
1.92
Total
SS Total =
7898.4
N-1=
14
SS Total / (N - 1) =
564.2
(c)
For = .025 and df = 2, 12, accept H0 if the computed F is # 5.10. Since F = 1.92, do not
reject H0. More formally,
Step 1.
H0: The 's all = 0 (i.e. prices are the same in each area)
HA: The 's are not all equal (prices not all the same)
Step 2.
Appropriate stat is
F = MS Between/ MS Within.
Since n = 15 and j = 3, d.f. = 2, 12.
Step 3.
Here is how you could solve this problem using SPSS. If using the SPSS pull-down menus, after
entering the data select ANALYZE/ COMPARE MEANS/ ONE WAY ANOVA.
* Problem 3.
Housing Prices.
Oneway
Descriptives
PRICE
N
1.00
2.00
3.00
Total
5
5
5
15
Mean
81.2000
77.0000
55.4000
71.2000
Std. Deviation
29.8781
20.5061
13.5019
23.7523
Std. Error
13.3619
9.1706
6.0382
6.1328
Minimum
40.00
59.00
40.00
40.00
Maximum
120.00
110.00
73.00
120.00
ANOVA
PRICE
Between Groups
Within Groups
Total
Sum of
Squares
1916.400
5982.000
7898.400
df
2
12
14
Mean Square
958.200
498.500
F
1.922
Sig.
.189
Comment: Some Anova routines would also report that R2 = .243. Note that R2 = SS Between
/ SS Total = 1916.4/7898.4 = .243. That is, R2 = Explained Variance divided by total variance.
We will talk more about R2 later.
F Test versus T Test. Finally, for good measure, we will do an F-Test vs. T-Test comparison.
We will do a modified version of problem 1, combining treatments 1 and 3 (the most effective),
and 2 and 4 (the least effective). Well let SPSS do the work.
* F test versus T-test comparison.
DATA LIST FREE / program score.
BEGIN DATA.
1
9
1 12
1 14
1 11
1 13
2 10
2
6
2
9
2
9
2 10
3 12
3 14
3 11
3 13
3 11
4
9
4
8
4 11
4
7
4
8
END DATA.
RECODE PROGRAM (1, 3 = 1) (2, 4 = 2).
ONEWAY
score BY program
/STATISTICS DESCRIPTIVES
/MISSING ANALYSIS .
Oneway
Descriptives
SCORE
N
1.00
2.00
Total
10
10
20
Mean
12.0000
8.7000
10.3500
Std. Deviation
1.5635
1.4944
2.2542
Std. Error
.4944
.4726
.5041
Minimum
9.00
6.00
6.00
Maximum
14.00
11.00
14.00
ANOVA
SCORE
Between Groups
Within Groups
Total
Sum of
Squares
54.450
42.100
96.550
df
Mean Square
54.450
2.339
1
18
19
F
23.280
Sig.
.000
T-Test
Group Statistics
SCORE
PROGRAM
1.00
2.00
N
10
10
Mean
12.0000
8.7000
Std. Error
Mean
.4944
.4726
Std. Deviation
1.5635
1.4944
F
SCORE
Equal variances
assumed
Equal variances
not assumed
.010
Sig.
.921
df
Sig. (2-tailed)
Mean
Difference
Std. Error
Difference
95% Confidence
Interval of the
Difference
Lower
Upper
4.825
18
.000
3.3000
.6839
1.8631
4.7369
4.825
17.963
.000
3.3000
.6839
1.8629
4.7371
COMMENT: Note that 4.822 = 23.28 (approximately), i.e. t2 = F. When you only have two
groups, both the F test and the T-Test are testing
H0:
HA:
1 = 2
1 2