SPSS FAQ
How can I do ANOVA contrasts in SPSS?
Let's use an example dataset, crf24, adapted from Kirk (1968,
First Edition).
get file 'd:\crf24.sav'.
These data are from a 2x4 factorial design but the same data can also be used for one-way ANOVA examples. The variable y is the dependent variable. The variable a is an independent variable with two levels, while b is an independent variable with four levels.
Using the contrast command in a one-way ANOVA
glm y by b.
Between-Subjects Factors
|
N |
| B |
1 |
8 |
| 2 |
8 |
| 3 |
8 |
| 4 |
8 |
Tests of Between-Subjects Effects
Dependent Variable: Y
| Source |
Type III Sum of Squares |
df |
Mean Square |
F |
Sig. |
| Corrected Model |
194.500(a) |
3 |
64.833 |
44.276 |
.000 |
| Intercept |
924.500 |
1 |
924.500 |
631.366 |
.000 |
| B |
194.500 |
3 |
64.833 |
44.276 |
.000 |
| Error |
41.000 |
28 |
1.464 |
|
|
| Total |
1160.000 |
32 |
|
|
|
| Corrected Total |
235.500 |
31 |
|
|
|
| a R Squared = .826 (Adjusted R Squared = .807)
|
means tables = y by b
/ cells mean.
Case Processing Summary
|
Cases |
| Included |
Excluded |
Total |
| N |
Percent |
N |
Percent |
N |
Percent |
| Y * B |
32 |
100.0% |
0 |
.0% |
32 |
100.0% |
Report
Mean
| B |
Y |
| 1 |
2.75 |
| 2 |
3.50 |
| 3 |
6.25 |
| 4 |
9.00 |
| Total |
5.38 |
It is quite clear that there is a significant overall F for the independent variable b
(F(3, 28) = 44.276, p = .000). Now, let's devise some contrasts that we can test:
1) group 3 versus group 4
2) the average of groups 1 and 2 versus the average of groups 3 and 4
3) the average of groups 1, 2, and 3 versus group 4
glm y by b
/contrast(b)=special (0 0 1 -1).
Between-Subjects Factors
|
N |
| B |
1 |
8 |
| 2 |
8 |
| 3 |
8 |
| 4 |
8 |
Tests of Between-Subjects Effects
Dependent Variable: Y
| Source |
Type III Sum of Squares |
df |
Mean Square |
F |
Sig. |
| Corrected Model |
194.500(a) |
3 |
64.833 |
44.276 |
.000 |
| Intercept |
924.500 |
1 |
924.500 |
631.366 |
.000 |
| B |
194.500 |
3 |
64.833 |
44.276 |
.000 |
| Error |
41.000 |
28 |
1.464 |
|
|
| Total |
1160.000 |
32 |
|
|
|
| Corrected Total |
235.500 |
31 |
|
|
|
| a R Squared = .826 (Adjusted R Squared = .807)
|
Contrast Results (K Matrix)
|
Dependent Variable |
| B Special Contrast |
Y |
| L1 |
Contrast Estimate |
-2.750 |
| Hypothesized Value |
0 |
| Difference (Estimate - Hypothesized)
|
-2.750 |
| Std. Error |
.605 |
| Sig. |
.000 |
| 95% Confidence Interval for Difference
|
Lower Bound |
-3.989 |
| Upper Bound |
-1.511 |
Test Results
Dependent Variable: Y
| Source |
Sum of Squares |
df |
Mean Square |
F |
Sig. |
| Contrast |
30.250 |
1 |
30.250 |
20.659 |
.000 |
| Error |
41.000 |
28 |
1.464 |
|
|
This contrast is statistically significant
(F(1, 28) = 20.659, p = .000).
glm y by b
/contrast(b)=special (1 1 -1 -1).
Between-Subjects Factors
|
N |
| B |
1 |
8 |
| 2 |
8 |
| 3 |
8 |
| 4 |
8 |
Tests of Between-Subjects Effects
Dependent Variable: Y
| Source |
Type III Sum of Squares |
df |
Mean Square |
F |
Sig. |
| Corrected Model |
194.500(a) |
3 |
64.833 |
44.276 |
.000 |
| Intercept |
924.500 |
1 |
924.500 |
631.366 |
.000 |
| B |
194.500 |
3 |
64.833 |
44.276 |
.000 |
| Error |
41.000 |
28 |
1.464 |
|
|
| Total |
1160.000 |
32 |
|
|
|
| Corrected Total |
235.500 |
31 |
|
|
|
| a R Squared = .826 (Adjusted R Squared = .807)
|
Contrast Results (K Matrix)
|
Dependent Variable |
| B Special Contrast |
Y |
| L1 |
Contrast Estimate |
-9.000 |
| Hypothesized Value |
0 |
| Difference (Estimate - Hypothesized)
|
-9.000 |
| Std. Error |
.856 |
| Sig. |
.000 |
| 95% Confidence Interval for Difference
|
Lower Bound |
-10.753 |
| Upper Bound |
-7.247 |
Test Results
Dependent Variable: Y
| Source |
Sum of Squares |
df |
Mean Square |
F |
Sig. |
| Contrast |
162.000 |
1 |
162.000 |
110.634 |
.000 |
| Error |
41.000 |
28 |
1.464 |
|
|
This contrast is also statistically significant (F(1, 28) = 110.634, p =
.000).
glm y by b
/contrast(b)=special (1 1 1 -3).
Between-Subjects Factors
|
N |
| B |
1 |
8 |
| 2 |
8 |
| 3 |
8 |
| 4 |
8 |
Tests of Between-Subjects Effects
Dependent Variable: Y
| Source |
Type III Sum of Squares |
df |
Mean Square |
F |
Sig. |
| Corrected Model |
194.500(a) |
3 |
64.833 |
44.276 |
.000 |
| Intercept |
924.500 |
1 |
924.500 |
631.366 |
.000 |
| B |
194.500 |
3 |
64.833 |
44.276 |
.000 |
| Error |
41.000 |
28 |
1.464 |
|
|
| Total |
1160.000 |
32 |
|
|
|
| Corrected Total |
235.500 |
31 |
|
|
|
| a R Squared = .826 (Adjusted R Squared = .807)
|
Contrast Results (K Matrix)
|
Dependent Variable |
| B Special Contrast |
Y |
| L1 |
Contrast Estimate |
-14.500 |
| Hypothesized Value |
0 |
| Difference (Estimate - Hypothesized)
|
-14.500 |
| Std. Error |
1.482 |
| Sig. |
.000 |
| 95% Confidence Interval for Difference
|
Lower Bound |
-17.536 |
| Upper Bound |
-11.464 |
Test Results
Dependent Variable: Y
| Source |
Sum of Squares |
df |
Mean Square |
F |
Sig. |
| Contrast |
140.167 |
1 |
140.167 |
95.724 |
.000 |
| Error |
41.000 |
28 |
1.464 |
|
|
This contrast is also statistically significant (F(1, 28) = 95.724, p =
.000).
Note that you can enter multiple contrasts in
a single subcommand, as shown below. Each contrast must be separated by a comma. While you get the significance
tests for each individual test,
you do not get the t-value. To obtain the t-value, you will have to divide the contrast estimate by the
std. error in the Contrast Results (K Matrix)
table.
glm y by b
/contrast(b)=special (0 0 1 -1, 1 1 -1 -1, 1 1 1 -3).
Between-Subjects Factors
|
N |
| B |
1 |
8 |
| 2 |
8 |
| 3 |
8 |
| 4 |
8 |
Tests of Between-Subjects Effects
Dependent Variable: Y
| Source |
Type III Sum of Squares |
df |
Mean Square |
F |
Sig. |
| Corrected Model |
194.500(a) |
3 |
64.833 |
44.276 |
.000 |
| Intercept |
924.500 |
1 |
924.500 |
631.366 |
.000 |
| B |
194.500 |
3 |
64.833 |
44.276 |
.000 |
| Error |
41.000 |
28 |
1.464 |
|
|
| Total |
1160.000 |
32 |
|
|
|
| Corrected Total |
235.500 |
31 |
|
|
|
| a R Squared = .826 (Adjusted R Squared = .807)
|
Contrast Results (K Matrix)
|
Dependent Variable |
| B Special Contrast |
Y |
| L1 |
Contrast Estimate |
-2.750 |
| Hypothesized Value |
0 |
| Difference (Estimate - Hypothesized)
|
-2.750 |
| Std. Error |
.605 |
| Sig. |
.000 |
| 95% Confidence Interval for Difference
|
Lower Bound |
-3.989 |
| Upper Bound |
-1.511 |
| L2 |
Contrast Estimate |
-9.000 |
| Hypothesized Value |
0 |
| Difference (Estimate - Hypothesized)
|
-9.000 |
| Std. Error |
.856 |
| Sig. |
.000 |
| 95% Confidence Interval for Difference
|
Lower Bound |
-10.753 |
| Upper Bound |
-7.247 |
| L3 |
Contrast Estimate |
-14.500 |
| Hypothesized Value |
0 |
| Difference (Estimate - Hypothesized)
|
-14.500 |
| Std. Error |
1.482 |
| Sig. |
.000 |
| 95% Confidence Interval for Difference
|
Lower Bound |
-17.536 |
| Upper Bound |
-11.464 |
Test Results
Dependent Variable: Y
| Source |
Sum of Squares |
df |
Mean Square |
F |
Sig. |
| Contrast |
192.250 |
2 |
96.125 |
65.646 |
.000 |
| Error |
41.000 |
28 |
1.464 |
|
|
Using the contrast command in a two-way ANOVA
Now let's try the same contrasts on
b but in a two-way ANOVA.
glm y by a b.
Between-Subjects Factors
|
N |
| A |
1 |
16 |
| 2 |
16 |
| B |
1 |
8 |
| 2 |
8 |
| 3 |
8 |
| 4 |
8 |
Tests of Between-Subjects Effects
Dependent Variable: Y
| Source |
Type III Sum of Squares |
df |
Mean Square |
F |
Sig. |
| Corrected Model |
217.000(a) |
7 |
31.000 |
40.216 |
.000 |
| Intercept |
924.500 |
1 |
924.500 |
1199.351 |
.000 |
| A |
3.125 |
1 |
3.125 |
4.054 |
.055 |
| B |
194.500 |
3 |
64.833 |
84.108 |
.000 |
| A * B |
19.375 |
3 |
6.458 |
8.378 |
.001 |
| Error |
18.500 |
24 |
.771 |
|
|
| Total |
1160.000 |
32 |
|
|
|
| Corrected Total |
235.500 |
31 |
|
|
|
| a R Squared = .921 (Adjusted R Squared = .899)
|
glm y by a b
/contrast(b)=special (0 0 1 -1).
Between-Subjects Factors
|
N |
| A |
1 |
16 |
| 2 |
16 |
| B |
1 |
8 |
| 2 |
8 |
| 3 |
8 |
| 4 |
8 |
Tests of Between-Subjects Effects
Dependent Variable: Y
| Source |
Type III Sum of Squares |
df |
Mean Square |
F |
Sig. |
| Corrected Model |
217.000(a) |
7 |
31.000 |
40.216 |
.000 |
| Intercept |
924.500 |
1 |
924.500 |
1199.351 |
.000 |
| A |
3.125 |
1 |
3.125 |
4.054 |
.055 |
| B |
194.500 |
3 |
64.833 |
84.108 |
.000 |
| A * B |
19.375 |
3 |
6.458 |
8.378 |
.001 |
| Error |
18.500 |
24 |
.771 |
|
|
| Total |
1160.000 |
32 |
|
|
|
| Corrected Total |
235.500 |
31 |
|
|
|
| a R Squared = .921 (Adjusted R Squared = .899)
|
Contrast Results (K Matrix)
|
Dependent Variable |
| B Special Contrast |
Y |
| L1 |
Contrast Estimate |
-2.750 |
| Hypothesized Value |
0 |
| Difference (Estimate - Hypothesized)
|
-2.750 |
| Std. Error |
.439 |
| Sig. |
.000 |
| 95% Confidence Interval for Difference
|
Lower Bound |
-3.656 |
| Upper Bound |
-1.844 |
Test Results
Dependent Variable: Y
| Source |
Sum of Squares |
df |
Mean Square |
F |
Sig. |
| Contrast |
30.250 |
1 |
30.250 |
39.243 |
.000 |
| Error |
18.500 |
24 |
.771 |
|
|
glm y by a b
/contrast(b)=special (1 1 -1 -1).
Between-Subjects Factors
|
N |
| A |
1 |
16 |
| 2 |
16 |
| B |
1 |
8 |
| 2 |
8 |
| 3 |
8 |
| 4 |
8 |
Tests of Between-Subjects Effects
Dependent Variable: Y
| Source |
Type III Sum of Squares |
df |
Mean Square |
F |
Sig. |
| Corrected Model |
217.000(a) |
7 |
31.000 |
40.216 |
.000 |
| Intercept |
924.500 |
1 |
924.500 |
1199.351 |
.000 |
| A |
3.125 |
1 |
3.125 |
4.054 |
.055 |
| B |
194.500 |
3 |
64.833 |
84.108 |
.000 |
| A * B |
19.375 |
3 |
6.458 |
8.378 |
.001 |
| Error |
18.500 |
24 |
.771 |
|
|
| Total |
1160.000 |
32 |
|
|
|
| Corrected Total |
235.500 |
31 |
|
|
|
| a R Squared = .921 (Adjusted R Squared = .899)
|
Contrast Results (K Matrix)
|
Dependent Variable |
| B Special Contrast |
Y |
| L1 |
Contrast Estimate |
-9.000 |
| Hypothesized Value |
0 |
| Difference (Estimate - Hypothesized)
|
-9.000 |
| Std. Error |
.621 |
| Sig. |
.000 |
| 95% Confidence Interval for Difference
|
Lower Bound |
-10.281 |
| Upper Bound |
-7.719 |
Test Results
Dependent Variable: Y
| Source |
Sum of Squares |
df |
Mean Square |
F |
Sig. |
| Contrast |
162.000 |
1 |
162.000 |
210.162 |
.000 |
| Error |
18.500 |
24 |
.771 |
|
|
glm y by a b
/contrast(b)=special (1 1 1 -3).
Between-Subjects Factors
|
N |
| A |
1 |
16 |
| 2 |
16 |
| B |
1 |
8 |
| 2 |
8 |
| 3 |
8 |
| 4 |
8 |
Tests of Between-Subjects Effects
Dependent Variable: Y
| Source |
Type III Sum of Squares |
df |
Mean Square |
F |
Sig. |
| Corrected Model |
217.000(a) |
7 |
31.000 |
40.216 |
.000 |
| Intercept |
924.500 |
1 |
924.500 |
1199.351 |
.000 |
| A |
3.125 |
1 |
3.125 |
4.054 |
.055 |
| B |
194.500 |
3 |
64.833 |
84.108 |
.000 |
| A * B |
19.375 |
3 |
6.458 |
8.378 |
.001 |
| Error |
18.500 |
24 |
.771 |
|
|
| Total |
1160.000 |
32 |
|
|
|
| Corrected Total |
235.500 |
31 |
|
|
|
| a R Squared = .921 (Adjusted R Squared = .899)
|
Contrast Results (K Matrix)
|
Dependent Variable |
| B Special Contrast |
Y |
| L1 |
Contrast Estimate |
-14.500 |
| Hypothesized Value |
0 |
| Difference (Estimate - Hypothesized)
|
-14.500 |
| Std. Error |
1.075 |
| Sig. |
.000 |
| 95% Confidence Interval for Difference
|
Lower Bound |
-16.719 |
| Upper Bound |
-12.281 |
Test Results
Dependent Variable: Y
| Source |
Sum of Squares |
df |
Mean Square |
F |
Sig. |
| Contrast |
140.167 |
1 |
140.167 |
181.838 |
.000 |
| Error |
18.500 |
24 |
.771 |
|
|
Note that the F-ratios in these contrasts are larger than the F-ratios in the one-way ANOVA example. This is
because the two-way ANOVA has a smaller mean square residual than the one-way ANOVA.
SPSS has a number of built-in contrasts that you can
use, of which special (used in the above examples) is only one. Below is a table listing those contrasts with an
explanation of the contrasts that they make and an example of how the syntax works. The repeated
contrast compares group 1 with 2,
2 with 3, and 3 with 4 as shown in the Contrast Results (K Matrix)
table in the results.
| Name of contrast |
Comparison made |
| Simple |
Compares each level of a variable to the last level (or
whichever level is specified) |
| Deviation |
Compares deviations from the grand mean |
| Difference |
Compares levels of a variable with the mean of the previous
levels of the variable |
| Helmert |
Compare levels of a variable with the mean of the subsequent
levels of the variable |
| Polynomial |
Orthogonal polynomial contrasts |
| Repeated |
Adjacent levels of a variable |
| Special |
User-defined contrast |
glm y by a b
/contrast(b)=repeated.
Between-Subjects Factors
|
N |
| A |
1 |
16 |
| 2 |
16 |
| B |
1 |
8 |
| 2 |
8 |
| 3 |
8 |
| 4 |
8 |
Tests of Between-Subjects Effects
Dependent Variable: Y
| Source |
Type III Sum of Squares |
df |
Mean Square |
F |
Sig. |
| Corrected Model |
217.000(a) |
7 |
31.000 |
40.216 |
.000 |
| Intercept |
924.500 |
1 |
924.500 |
1199.351 |
.000 |
| A |
3.125 |
1 |
3.125 |
4.054 |
.055 |
| B |
194.500 |
3 |
64.833 |
84.108 |
.000 |
| A * B |
19.375 |
3 |
6.458 |
8.378 |
.001 |
| Error |
18.500 |
24 |
.771 |
|
|
| Total |
1160.000 |
32 |
|
|
|
| Corrected Total |
235.500 |
31 |
|
|
|
| a R Squared = .921 (Adjusted R Squared = .899)
|
Contrast Results (K Matrix)
|
Dependent Variable |
| B Repeated Contrast |
Y |
| Level 1 vs. Level 2 |
Contrast Estimate |
-.750 |
| Hypothesized Value |
0 |
| Difference (Estimate - Hypothesized)
|
-.750 |
| Std. Error |
.439 |
| Sig. |
.100 |
| 95% Confidence Interval for Difference
|
Lower Bound |
-1.656 |
| Upper Bound |
.156 |
| Level 2 vs. Level 3 |
Contrast Estimate |
-2.750 |
| Hypothesized Value |
0 |
| Difference (Estimate - Hypothesized)
|
-2.750 |
| Std. Error |
.439 |
| Sig. |
.000 |
| 95% Confidence Interval for Difference
|
Lower Bound |
-3.656 |
| Upper Bound |
-1.844 |
| Level 3 vs. Level 4 |
Contrast Estimate |
-2.750 |
| Hypothesized Value |
0 |
| Difference (Estimate - Hypothesized)
|
-2.750 |
| Std. Error |
.439 |
| Sig. |
.000 |
| 95% Confidence Interval for Difference
|
Lower Bound |
-3.656 |
| Upper Bound |
-1.844 |
Test Results
Dependent Variable: Y
| Source |
Sum of Squares |
df |
Mean Square |
F |
Sig. |
| Contrast |
194.500 |
3 |
64.833 |
84.108 |
.000 |
| Error |
18.500 |
24 |
.771 |
|
|
For more information on coding contrasts,
please see How can I use the lmatrix subcommand to understand a three-way interaction
in ANOVA? .References
Kirk, Roger E. (1968) Experimental Design: Procedures for the Behavioral Sciences.
Monterey, California: Brooks/Cole Publishing.
The content of this web site should not be construed as an endorsement
of any particular web site, book, or software product by the
University of California.