### SPSS Textbook Examples Design & Analysis by Keppel Chapter 16

Chapter 16

#### Chapter 16: The Single-Factor  Within-Subjects Design

Example 16.1. Single-Factor Within-Subjects Design, Overall Analysis, Pages 348-349 of Keppel.
Example 16.1a. SPSS MANOVA, Wide File
Example 16.1b. SPSS GLM, Wide File
Example 16.1c. SAS PROC GLM, Wide File
Example 16.1d. SPSS MANOVA, Narrow File
Example 16.1e. SAS PROC GLM, Narrow File
Example 16.1f. SPSS GLM, Narrow File
Example 16.1g SAS PROC MIXED, Narrow File
Example 16.2. Comparisons Involving the Treatment Means, Pages 356-358 of Keppel.
Example 16.2a. SPSS MANOVA, Wide File
Example 16.2c. SAS PROC GLM, Wide File
Example 16.2d. SPSS MANOVA, Narrow File
Example 16.3 Removing Practive Effects from the Error Term, Pages 361-363.
Example 16.3a. SPSS MANOVA, Narrow File
Example 16.3b. SPSS GLM, Narrow File
Example 16.3c. SAS PROC GLM, Narrow File
Example 16.3d SAS PROC MIXED, Narrow File

Example 16.1. Single-Factor Within-Subjects Design, Overall Analysis, Pages 348-349 of Keppel.

There are a wide variety of strategies which can be used to analyze data from studies involving within subjects variables (also known as repeated measures variables). One major distinction is whether the data is entered as a wide file, or as a narrow file. A wide file enters all of the scores for the within subjects variable on the same record, as shown in the CHAP16W (SPSS, SAS) data file. By contrast, a narrow file enters each score on a separate record, as shown in the CHAP16N (SPSS, SAS) data file. A wide file can be analyzed using SPSS manova, SPSS glm, and SAS proc glm. A narrow file can be analyzed using SPSS manova, SAS proc glm, SPSS glm, and SAS proc mixed. Examples of each of these analyses is shown below. The analyses on wide files use the CHAP16W (SPSS, SAS) data file, and the analyses on narrow files use the CHAP16N (SPSS, SAS) data file.

Example 16.1a. SPSS MANOVA, Wide File

MANOVA score1 score2 score3
/WSFACTORS a(3).

This example shows how to analyze a wide file in SPSS manova. The variables score1 score2 score3 represent the value of the dependent variable at the three levels of the within subjects variable. The /wsfactors a(3) subcommand is used to indicate that there is a within-subjects variable named a and that it has 3 levels (which correspond to score1 score2 score3 from the manova command.

The SPSS manova output displays the Greenhouse-Geisser Epsilon, Huynh-Feldt Epsilon, and Lower-bound Epsilon which can be used to adjust df to compensate for violation of the sphericity assumption. However, SPSS glm (as discussed below) will adjust the df for you, and compute the adjusted p-values based on the adjusted df.

Example 16.1b. SPSS GLM, Wide File

GLM score1 score2 score3
/WSFACTORS a(3).

SPSS glm uses virtually the exact same syntax as SPSS manova for analyzing a single-factor within-subjects design (see Example 16.1a). The list of variables comprising the within subjects variable is given on the glm command (i.e., glm score1 score2 score3) and the /wsfactors a(3) subcommand is used to indicate that score1 score2 score3 actually compose the three levels of the within subjects variable called a.

Despite the similarity in syntax, SPSS glm offers some additional output not found in the SPSS manova output. SPSS glm will show tests where Sphericity is Assumed (the default) as well as Greenhouse-Geisser, Huynh-Feldt, and Lower-bound tests. To show these tests, double click the Tests of Within Subjects Effects pivot table, and then on the Pivot pull down menu, choose Move Layers to Rows.

Example 16.1c. SAS PROC GLM, Wide File

PROC GLM DATA=chap16w;
MODEL score1 score2 score3 = ;
REPEATED a 3;
RUN;

SAS proc glm approaches a single-factor within-subjects design in much the same way as SPSS manova and SPSS glm. The left side of the model model statement lists the variables which comprise the within-subjects factor. (It may seem strange that there are no effects on the right side of the equal sign of the model statement, but this is correct.) The repeated statement is used to indicate that there is a within-subjects variable named a with three levels, which corresponds to the three variables on the left side of the equal sign on the model statement, score1 score2 score3.

In addition to standard output, SAS proc glm also provides Greenhouse-Geisser and Huynh-Feldt tests (labeled G -G and H - F, respectively).

Example 16.1d. SPSS MANOVA, Narrow File

MANOVA score BY a(1,3) s(1,6)
/DESIGN = a*s=1, a VS 1, s.

SPSS manova can also be used to analyze within-subjects design using narrow data, but it is necessary to manually specify the effects and error terms for the analyses. The syntax of the manova command appears like this is a factorial between subjects design with two factors, a and s. Actually, a represents the levels of the within subjects factor, and s indicates the subject number. If the /design subcommand were omitted, SPSS would indeed analyze this data as though it were from a between subjects factorial design. This is why it is necessary to use the /design subcommand to specify the appropriate effects and error terms to test.

As Keppel shows, the ANOVA table includes the effects a s and a*s with the effect of a being testing using a*s as the error term. These effects are defined manually on the /design subcommand. The a*s=1 effect indicates that a*s is an effect, and that it can be used as a error term using the alias of 1. Then, a vs 1 indicates that a should be tested against the effect aliased as 1 (i.e., a*s). And finally s is included as an effect as well.

Example 16.1e. SAS PROC GLM, Narrow File

PROC GLM DATA=chap16n;
CLASS a s;
MODEL score = a s a*s;
TEST h=a e=a*s;
RUN;

SAS proc glm can also be used to analyze data for a within-subjects design using a narrow data file. The strategy is much like SPSS manova with a narrow data file. The within-subjects factor and the variable indicating subjects is given in the class statement. The model statement includes all of the effects shown in the ANOVA table shown in Keppel (i.e., a s a*s). The test statement is used to manually test the effect of a using a*s as the error term.

Example 16.1f. SPSS GLM, Narrow File

GLM score BY a s
/RANDOM s
/DESIGN a s.

SPSS glm can be used to analyze data from a within subjects design using a narrow data file. The within-subjects variable, and the variable indicating subjects is given on the glm command (i.e., glm score by a s). The /random subcommand is used to indicate that factor s (subjects) is a random factor. The /design subcommand is used to tell SPSS to include the factors a and s in the design. SPSS glm uses the information in the /design subcommand to determine which effects to test, and uses the /random subcommand to determine the appropriate error terms for all effects to be tested.

Example 16.1g SAS PROC MIXED, Narrow File

PROC MIXED DATA=chap16n;
CLASS a s;
MODEL score = a ;
REPEATED / SUBJECT=s TYPE=CS;
RUN;

This final example shows how to use SAS proc mixed to analyze data from a within-subjects design using a narrow data file (in fact, proc mixed cannot analyze data from wide data files). The class statement includes the within-subjects factor, and the variable indicating subjects. The model statement includes only the within subjects factor on the right side of the equation. The repeated statement is used to indicate that the data comes from a repeated measures (within-subjects) design. The subject=s indicates that the variable s indicates the different subjects, and type=cs specifies that the covariance matrix is assumed to have the structure of compound symmetry. Other covariance structures can be specified, such as variance components (type=vc), auto-regressive (type=ar), or unstructured (type=un).

16.1 Summary

Each of these analyses strategies offers some benefits and drawbacks. In general, the strategies analyzing the wide data files offer the benefit of automatic selection of the appropriate error term, and with SPSS glm and SAS proc glm the automatic computation of adjusted tests which attempt to compensate for violation of sphericity assumptions. By contrast, the strategies involving narrow data files can be more demanding. For example, SPSS manova and SAS proc glm require the manual specification of the effects to be tested, and error terms to be used and these strategies do not provide any statistics regarding violation of sphericity assumptions. Finally, SPSS glm and SAS proc mixed automatically select the appropriate effects and error terms, but also do not provide statistics regarding violation of sphericity assumptions. However, SAS proc mixed is the only procedure which permits the selection among a variety of covariance structures to appropriately model the covariance among the repeated measures.

Example 16.2. Comparisons Involving the Treatment Means, Pages 356-358 of Keppel.

Suppose you wish to compare a2 to (a1 and a3) as shown on page 357 of Keppel. As recommended by Keppel, this comparison should be made using MSAcomp. x s as the error term. Of the seven strategies shown above, only three were found to use the error term recommended by Keppel, SPSS manova with a wide file, SAS proc glm with a wide file, and SPSS manova with a narrow file. All of the other methods used MSA x s as the error term.  The analyses on wide files use the CHAP16W (SPSS, SAS) data file, and the analyses on narrow files use the CHAP16N (SPSS, SAS) data file.

Example 16.2a. SPSS MANOVA, Wide File

MANOVA score1 score2 score3
/WSFACTORS a(3)
/CONTRAST(a) = SPECIAL(1  1  1
1 -2  1
1  0 -1)
/WSDESIGN = a(1) a(2).

This example resembles Example 16.1a in the syntax of the manova command and the /wsfactors subcommand. The /contrasts subcommand is used to compare a2 with (a1 and a3). (See Example 11.1a for more information on the /contrast subcommand). Because a was created using /wsfactors, the effect a(1) is must be listed in the /wsdesign subcommand, not the /design subcommand. Factors listed after the by clause of the manova command can be entered on the /design, and factors created by the /wsfactors subcommand can be entered on the /wsdesign subcommand.

You may be alarmed if you compare the output of this program with the results shown by Keppel on page 358. The sums of squares and mean squares from the output will differ from those shown by Keppel, although the final F-ratio is correct. As Keppel describes on pages 359-360, the sums of squares can be standardized so they are independent of the coefficients selected. The standardized values shown on page 360 correspond to those shown in the output of this example.

Example 16.2b. SAS PROC GLM, Wide File

PROC GLM DATA=chap16w;
MODEL score1 score2 score3 = ;
REPEATED a 3 POLYNOMIAL / SUMMARY ;
RUN;

This example is extremely similar to Example 16.1c. The only difference is that polynomial / summary is added to the repeated statement, which are included to request the comparison of a2 with (a1 and a3). The polynomial keyword applies orthogonal polynomial transformations (i.e., linear and quadratic) to the repeated factor, and the summary option requests the output of these polynomial transformations to be displayed. The quadratic term applies the coefficients 1 -2 1 to factor a, which corresponds to the comparison of interest. The output of this contrast is labeled as the second order polynomial contrast applied to factor A.

SAS provides a limited set of pre-defined contrasts which can be applied to within-subjects factors via the repeated statement. Had this contrast not been one of the pre-defined contrasts, this strategy could not have been used.

Example 16.2c. SPSS MANOVA, Narrow File

MANOVA score BY a(1,3) s(1,6)
/CONTRAST(a) = SPECIAL(1  1  1
1 -2  1
1  0 -1)
/DESIGN = a(1)*s=1, a(1) VS 1, s.

This example is somewhat like Example 16.1d, which showed how to perform a basic within-subjects analysis using a narrow file. The /contrast subcommand is used to form the comparison of a2 with (a1 and a3) (see Example 11.1a for more information about the /contrast subcommand). The /design subcommand is used to specify the effects and error terms. The term a(1)*s=1 indicates that a(1)*s is an effect, and that it can be used as an error term using the alias of 1. The term a(1) vs 1 indicates that a(1) should be tested against the error term aliased as 1 (i.e. a(1)*s). (Remember, that Keppel recommends Acomp*s as the error term, not a*s.) Finally, s indicates that s should be included in the model.

16.2 Summary

Of the three strategies shown, SPSS manova with a wide file seems the most flexible and simple to use. It automatically used the desired error term (Acomp*s) and it permits the entry of any valid comparison in the special matrix. Using SPSS manova with a narrow file is equally flexible, but it requires that the user enter the appropriate effects and error terms. Finally, SAS proc glm offers the benefit that it uses the desired error term, but the contrasts which can be used are limited.

Example 16.3 Removing Practice Effects from the Error Term, Pages 361-363.

Suppose you wish to perform an analysis similar to the one shown in Example 16.1, but also remove the practice effects (i.e., the effect of position). In such an analysis, the repeated measurements represent two different factors, differences in factor a and differences in position (p). Such an analysis can only be performed using a narrow dataset, because such a dataset can indicate both the level of a and level of p for each trial. As Keppel's example shows, this design includes the effects A, S, and P, and the effects A and P are both tested using A X S(residual) as the error term. These examples include using SPSS manova, SPSS glm, SAS proc glm and SAS proc mixed.   These analyses use the CHAP16N (SPSS, SAS) data file.

Example 16.3a. SPSS MANOVA, Narrow File

MANOVA score BY a(1,3) p(1,3) s(1,6)
/DESIGN = a VS RESIDUAL, s, p VS RESIDUAL.

This example resembles Example 16.1d. This example includes three factors after the by statement, a, p and s. The /design subcommand indicates the effects to be tested, and error terms to be used. The effect a is to be tested against residual. The keyword residual means the variance which remains after including all of the hypothesized effects included in the /design subcommand. The effect s is to be included in the model, and the effect p will be tested against residual.

Example 16.3b. SPSS GLM, Narrow File

GLM score BY a s p
/RANDOM s
/DESIGN a s p.

This program is virtually identical to the one shown in 16.1f. The only changes needed to include the effect of position is to add p to the by clause and to the /design subcommand.

Example 16.3c. SAS PROC GLM, Narrow File

PROC GLM DATA=chap16n;
CLASS a s p;
MODEL score = a s p ;
RUN;

This example is somewhat similar to example 16.1e. The class statement includes factors a s p. The model statement includes the factors of interest, a s p. The effects specified in the model statement will be tested against MSresidual (the desired error term).

Example 16.3d. SAS PROC MIXED, Narrow File

PROC MIXED DATA=chap16n;
CLASS a s p;
MODEL score = a p ;
REPEATED / TYPE=CS SUBJECT=s;
RUN;

This example is nearly identical to example 16.1g. To include the effect of position, the effect p is added to the class statement, and the effect p is added to the model statement.

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.