Two-factor within-subjects ANOVA

The following example shows how to use the SPSS MIXED procedure to estimate a two-factor within-subjects ANOVA with missing values on the repeated measures variables.

The typical data setup for a two-factor within-subjects ANOVA has the repeated measures variables as separate columns (i.e., wide format).  For example, consider a design where factor A has two levels (a1 and a2) and factor B has three levels (b1, b2, and b3).  The data would look like this.

In order to use the SPSS mixed procedure to implement maximum likelihood estimation, the data must be stacked, such that the repeated measures variables appear in a single column and each case has multiple rows of data.  The stacked file would look like this.

The VARSTOCASES command (from the pull-downs, choose DATA then RESTRUCTURE) stacks the data file.  The syntax for the above example is as follows.


   /make dv from a1b1 a1b2 a1b3 a2b1 a2b2 a2b3

   /index = condition (6)

   /keep id

   /null = keep.

recode condition(1 thru 3 = 1)(4 thru 6 = 2) into wsfactora.

recode condition (1,4 = 1)(2,5 = 2)(3,6 = 3) into wsfactorb.


Finally, the MIXED syntax for the analysis is as follows.  The EMMEANS subcommands give maximum likelihood mean estimates and significance tests for the main effects and simple effects.

* the first emmeans line compares factor b separately within levels of factor a.

* the second emmeans line compares the main effect of factor a.

* the third emmeans line compares the main effect of factor b.

mixed dv by wsfactora wsfactorb

   /method = ml

   /print = testcov

   /emmeans = tables (wsfactora*wsfactorb) compare(wsfactorb) 

   /emmeans = tables (wsfactora) compare(wsfactora) 

   /emmeans = tables (wsfactorb) compare(wsfactorb) 

   /fixed = wsfactora wsfactorb wsfactora*wsfactorb

   /repeated = wsfactora*wsfactorb | subject(id) covtype(cs).

The previous analysis specifies a compound symmetric covariance structure that is consistent with a standard repeated measures ANOVA.  Changing the covariance structure from CS to UN implements an unstructured covariance matrix (less stringent assumptions, more estimated parameters).  The square root of the diagonal elements in the estimated covariance matrix are maximum likelihood standard deviations.

Questions or suggestions? Email Craig Enders