SAS Textbook Examples Design and Analysis by Keppel Chapter 11

Chapter 11

Chapter 11: Detailed Analyses of Main Effects and Simple Effects

11.1 Comparison of Marginal Means, Page 234 of Keppel
Example 11.1a..SPSS MANOVA
Example 11.1b. SPSS GLM
Example 11.1c. SAS PROC GLM
11.2 Analyzing Simple Effects, Page 141 of Keppel

Example 11.2a. SPSS MANOVA
Example 11.2b SPSS GLM
Example 11.2c SAS PROC GLM
11.3 Analyzing Simple Comparisons, Page 246 of Keppel

Example 11.3a. SPSS MANOVA
Example 11.3b SPSS GLM
Example 11.3c SAS PROC GLM

11.1 Comparison of Marginal Means, Page 234 of Keppel

Assume you wish to perform a comparison of marginal means comparing level a1 to a3 as shown on page 234 of section 11.1 in Keppel. This can be analyzed using SPSS manova, SPSS glm, or SAS glm. All of these examples use the CHAP10 (SPSS, SAS) data file.

Example 11.1a. SPSS MANOVA

 MANOVA errors BY a(1,3) b(1,2)
/ERROR = W
/CONTRAST(a) = SPECIAL(1  1  1
1  0 -1
1 -2  1)
/DESIGN = a(1) a(2) b
a by b. 

The /contrast subcommand supplies the contrast coefficients to be applied to factor A. The first row of coefficients is a series of 1's (corresponding to the number of levels of factor A). This row is always required. The coefficients in the second and third row form the first and second contrast applied to factor A. The second row specifies the contrast of interest, comparing a1 to a3. Because the special matrix must be square, a third row of coefficients is required (preferably orthogonal to the previous rows), hence the third row comparing a2 to (a1 & a3) was included.

The /design = a(1) subcommand tells SPSS to test the effect of the first contrast applied to a (i.e. the second row of the special matrix). Therefore, the /design = a(1) subcommand tells SPSS to compare a1 to a3, the comparison of interest. The /error=w subcommand tells SPSS to use the within cells variance for computing the error term (some versions of SPSS use WITHIN+RESIDUAL as the error term).

Example 11.1b. SPSS GLM

 GLM errors BY a b
/LMATRIX = 'a1 vs. a3' a 1
0
-1
a*b 1/2  1/2
0    0
-1/2 -1/2 . 

The /lmatrix subcommand is used to in this example to compare a1 to a3. As this example shows, the contrast coefficients of 1 0 -1 are applied to a. For the contrast to be estimable in SPSS glm (version 7.5 or below), contrast coefficients must be supplied for any higher order effects which are present in the model. In this example, there is a higher order effect present, the a*b interaction. The coefficients applied to a must be distributed evenly across a*b for the test to be estimable.  This is the reason for the coefficients which are applied to a*b in the /lmatrix subcommand in this example. It is possible that this requirement may be removed in future versions of SPSS glm.

Example 11.1c. SAS PROC GLM

 PROC GLM DATA=chap10;
CLASS a b;
MODEL errors = a b a*b;
CONTRAST 'a1 vs a3' a 1
0
-1 ;
RUN; 

The contrast subcommand is used in proc glm to compare a1 to a3. As this example shows, the contrast coefficients of 1 0 -1 are applied to a to perform this comparison. Note that unlike SPSS glm, it is not necessary to provide contrast coefficients for the higher order effects. SAS proc glm automatically performs this distribution for you.

Summary: 11.1 Comparison of Marginal Means

SPSS manova and SAS proc glm seem to offer the simplest method of obtaining simple comparisons. SPSS manova adds the additional burden that you must supply a square matrix of (preferably orthogonal) contrast coefficients, whereas SAS proc glm permits you to supply only the contrasts you wish to test in the contrast statement. When analyzing a factorial design, SPSS glm poses the complication of needing to supply contrast coefficients for not only the effect of interest, but also all higher order interactions involving that effect

11.2 Analyzing Simple Effects, Page 241 of Keppel

In section 11.3, page 241, Keppel shows how to test the simple effect of "A at b1" and "A at b2" This analysis can be performed in SPSS manova, SPSS glm, or SAS proc glm. All of these examples the CHAP10 (SPSS, SAS) data file.

Example 11.2a. SPSS MANOVA

 MANOVA errors BY a(1,3) b(1,2)
/ERROR = W
/DESIGN = b
a WITHIN b(1)
a WITHIN b(2). 

The /design subcommand is used to specify a simple effect. In this example, the a within b(1) effect tests the effect of "A at b1", and the a within b(2) effect tests the effect of "A at b2". The /error=w subcommand is used to use the within cells variance as the error term.

Example 11.2b. SPSS GLM

 GLM errors BY a b
/EMMEANS TABLES(a*b) COMPARE(a). 

Simple effects in SPSS GLM can be requested using the /emmeans subcommand with the tables(a*b) and compare(a) options. In this example, these options request the simple effect of factor A at each level of factor B, in this case the simple effect of "A at b1" and "A at b2". Note that the compare option became available in SPSS version 7.5.

Example 11.2c. SAS PROC GLM

 PROC GLM DATA=chap10;
CLASS a b;
MODEL errors = a b a*b;
LSMEANS a*b / SLICE = b;
run; 

Simple effects can be requests in SAS proc glm using the lsmeans command with the slice option. The slice = b option requests that the a*b interaction be examined at each level of factor A, in other words it requests the simple effect of "A at b1" and "A at b2".

Summary: 11.2 Analyzing Simple Effects

There are no striking advantages or disadvantages among the three strategies shown for obtaining simple effects. Each of these strategies offer a straightforward method of requesting simple effects.

11.3 Analyzing Simple Comparisons, Page 246 of Keppel

On page 246 of Keppel, simple comparisons are illustrated comparing a1 to a2 at B1 and a1 to a2 at B2. This simple comparison can be performed in SPSS manova, SPSS glm, and SAS proc glm as shown in the following examples. These examples use the CHAP10 (SPSS, SAS) data file.

Example 11.3a. SPSS MANOVA.

 MANOVA errors BY a(1,3) b(1,2)
/ERROR = W
/CONTRAST(a) = SPECIAL(1  1  1
1 -1  0
1  1 -2)
/DESIGN = b
a(1) WITHIN b(1)
a(1) WITHIN b(2)
a(2) WITHIN b(1)
a(2) WITHIN b(2). 

The /contrast subcommand is used to supply the contrast coefficients to compare a1 to a2 (via the second row of the special matrix, 1 -1 0). The /design subcommand is used to specify the simple comparison, "Acomp. at b1" . For example, a(1) within b(1) means to compare "a1 to a2 at B1". The /error = w subcommand instructs SPSS to use the within cells variance as the error term.

Example 11.3b. SPSS GLM.

 GLM errors BY a b
/LMATRIX = 'a1 vs a2 at b1' a  1
-1
0
a*b  1  0
-1  0
0  0
/LMATRIX = 'a1 vs a2 at b2' a  1
-1
0
a*b  0  1
0 -1
0  0.  

In SPSS glm, the /lmatrix subcommand is used to request a simple comparison. The first /lmatrix subcommand requests the comparison of a1 versus a2 at B1. Such a comparison is requested by simultaneously applying contrast coefficients to a and to a*b. The "a1 versus a2 at B1" effect is requested by applying a contrast to factor a which compares a1 versus a2 (i.e., 1 -1 0) and a contrast to a*b which compares a1 versus a2 only within B1. Think of the contrast coefficients applied to a*b as having 3 rows corresponding to the three levels of A and 2 columns corresponding to the 2 levels of B, as illustrated below.

         b1	b2
a1	 1	0
a2	-1	0
a3	 0	0

The second /lmatrix subcommand also requests a simple comparison of "a1 vs a2 at B2". The coefficients applied to a are the same as the first example because both compare a1 vs a2. The difference lies in the contrasts applied to a*b. In the second example, the contrast is in the second column of the a*b matrix, indicating that the comparison takes place within B2.

Note: It may appear that a represents rows and b represents columns because the term a*b was used in the /lmatrix subcommand. Actually, this ordering is determined by the order of the variables in the glm command. Because a preceded b in the glm command, a represents rows and b represents columns.

The a*b matrix can also be thought of as one long vector where a increments slowest, and b increments faster (because a appeared first in the glm command it increments slowest). Hence, the items in the a*b contrast matrix are in the following order,

a1b1    a1b2     a2b1    a2b2     a3b1    a3b2

Example 11.3c. SAS PROC GLM.

 PROC GLM DATA=chap10;
CLASS a b;
MODEL errors = a b a*b;
CONTRAST 'a1 vs a2 at b1'   a  1
-1
0
a*b  1  0
-1  0
0  0 ;
CONTRAST 'a1 vs a2 at b2'   a  1
-1
0
a*b  0  1
0 -1
0  0;
RUN; 

When using SAS proc glm, the contrast command is used to request a simple comparison. Comparing Example 11.3b with Example 11.3c shows that SPSS glm and SAS proc glm use the same contrast coefficients to request a simple comparisons. Please refer to to example 11.3b for an explanation of how the contrast coefficients were chosen to request this simple comparison.

Note: It may appear that a represents rows and b represents columns because the term a*b was used in the contrast subcommand. Actually, this ordering is determined by the order of the variables in the class command. Because a preceded b in the class command, a represents rows and b represents columns.

The a*b matrix can also be thought of as one long vector where a increments slowest, and b increments faster (because a appeared first in the class command it increments slowest). Hence, the items in the a*b contrast matrix are in the following order,

a1b1    a1b2     a2b1    a2b2     a3b1    a3b2

Summary: 11.3 Analyzing Simple Comparisons

SPSS manova may offer the simplest strategy for requesting simple comparisons because it does not require the coding of contrast coefficients like SPSS glm and SAS proc glm. Constructing contrast coefficients for simple comparisons can be very tricky, and there are very few checks to ensure that the contrast you have input corresponds to the contrast you truly desire. If there are features in SPSS glm or SAS proc glm which provide a compelling reason for using these programs, it may be prudent to run the same analysis in SPSS manova to double check the results.

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.