* ================================================================== * FILE: mixed003 repeated measures ANOVA.sps . * NOTES: Use MIXED procedure to perform repeated measures ANOVA . * DATE: 4-Apr-2008 . * AUTHOR: Bruce Weaver, bweaver@lakeheadu.ca . * ================================================================== . define !spss ()'C:\Program Files\SPSS\'!enddefine. * NOTE: As of version 16, the sample data files are in * the ..\Samples\" folder in the main SPSS folder. * If you are using a version that does not have that * folder, remove "samples\" from the GET FILE line below. get file = !spss + 'samples\Growth study.sav' . * Perform repeated measurs ANOVA with the * GLM, UNIANOVA and MIXED procedures . * GLM REPEATED MEASURES requires one row per ID. * Use CASESTOVARS to restructure the data . CASESTOVARS /ID = subject /fixed = gender /drop = index /SEP="". GLM distance1 distance2 distance3 distance4 /WSFACTOR = age 4 Polynomial /METHOD = SSTYPE(3) /PLOT = PROFILE( age ) /EMMEANS = TABLES(age) /WSDESIGN = age . * UNIANOVA and MIXED require one row per observation, so revert * to the original data file. get file = !spss + 'samples\Growth study.sav' . UNIANOVA distance BY age subject /RANDOM = subject /METHOD = SSTYPE(3) /PLOT = PROFILE( age ) /EMMEANS = TABLES(age) /DESIGN = age subject . * Note that the SEs from UNIANOVA (in the table of estimated * marginal means) do not agree with those from GLM-Repeated * Measures. Nor do they agree with the SEs that MIXED * produces with either CS or UN as the COVTYPE (see below). * When you use the MIXED procedure, you have to declare the * repeated measures factor (AGE in this example) as both * FIXED and REPEATED. If you omit the declaration of age * as FIXED, you don't get the F-test for age in the output. MIXED distance BY age /FIXED = age | SSTYPE(3) /REPEATED = age | SUBJECT(subject) COVTYPE(cs) /EMMEANS = TABLES(age) . * The SPSS Manual suggests specifying CS (compound symmetry) * as the COVTYPE (covariance type) for this design. * However, when you do, the standard error is the same for * all levels of the repeated measures factor (in the table * of estimated marginal means). * To get the same SEs that you get with GLM-Repeated Measures, * you have to set COVTYPE to UN (unspecified), as shown below. MIXED distance BY age /FIXED = age | SSTYPE(3) /REPEATED = age | SUBJECT(subject) COVTYPE(un) /EMMEANS = TABLES(age) . * -------------------------------------------------- . freq age. * Note that each child was measured at the same 4 values of age, * 8, 10, 12, and 14. Therefore, another option would be to * treat age as a continuous variable. * I do so below, and allow both the intercept and slope * to be random across subjects. MIXED distance WITH age /FIXED=age | SSTYPE(3) /METHOD=ML /PRINT=SOLUTION /RANDOM intercept age | SUBJECT(subject) COVTYPE(UN) . * Now see if the fit of the model improves when we allow * the age effect to be curvilinear. compute age2 = age**2. var lab age2 "age^2". MIXED distance WITH age age2 /FIXED=age age2 | SSTYPE(3) /METHOD=ML /PRINT=SOLUTION /RANDOM intercept age | SUBJECT(subject) COVTYPE(UN) . * Change in -2LL from previous model is trivial. * What if I allow the age^2 effect to be random? . MIXED distance WITH age age2 /FIXED=age age2 | SSTYPE(3) /METHOD=ML /PRINT=SOLUTION /RANDOM intercept age age2 | SUBJECT(subject) COVTYPE(UN) . * Convergence not achieved--parameters could not be estimated. * Therefore, revert to the model with a random intercept * and random slope for age, without age-squared in the model. * This makes sense, given the line graphs shown earlier. * ================================================================== .