* ================================================================== FILE: repmeas_ANOVA_with_long_file.sps NOTES: Use GLM UNIANOVA with subject as a random factor to perform repeated measures ANOVA DATE: 26-Jun-2003 AUTHOR: Bruce Weaver, weaverb@mcmaster.ca * ================================================================== . * Read in some data in both WIDE and LONG format. * That is, file has 3 rows per subject, with all 3 of the repeated * measures on row 1 for each person (WIDE file format). * But variable DV = A1 on row 1, A2 on row 2, and A3 on row 3 (LONG format). DATA LIST LIST /id(f2.0) cond (f2.0) dv(f5.0) a1(F5.0) a2(F5.0) a3(f5.0) . BEGIN DATA. 1 1 7 7 3 2 1 2 3 99 99 99 1 3 2 99 99 99 2 1 4 4 8 3 2 2 8 99 99 99 2 3 3 99 99 99 3 1 7 7 6 3 3 2 6 99 99 99 3 3 3 99 99 99 4 1 8 8 6 1 4 2 6 99 99 99 4 3 1 99 99 99 5 1 7 7 2 3 5 2 2 99 99 99 5 3 3 99 99 99 6 1 6 6 3 3 6 2 3 99 99 99 6 3 3 99 99 99 7 1 4 4 2 0 7 2 2 99 99 99 7 3 0 99 99 99 8 1 6 6 7 5 8 2 7 99 99 99 8 3 5 99 99 99 END DATA. miss val dv a1 to a3 (99). * Do repeated measures ANOVA, in usual fashion * (WIDE format with one row per subject). GLM a1 a2 a3 /WSFACTOR = a 3 Polynomial /METHOD = SSTYPE(3) /EMMEANS = TABLES(a) /PRINT = DESCRIPTIVE /CRITERIA = ALPHA(.05) /WSDESIGN = a . * Now do a GLM with 3 rows per subject, and subject as a random factor . * This should produce the same F-test as the repeated measures ANOVA above . UNIANOVA dv BY id cond /RANDOM = id /METHOD = SSTYPE(3) /INTERCEPT = INCLUDE /EMMEANS = TABLES(cond) /CRITERIA = ALPHA(.05) /DESIGN = id cond . * GLM UNIANOVA yields the same F-ratio and p-value as the repeated measures ANOVA performed earlier . * Now repeat, but make ID a fixed factor . UNIANOVA dv BY id cond /METHOD = SSTYPE(3) /INTERCEPT = INCLUDE /EMMEANS = TABLES(cond) /CRITERIA = ALPHA(.05) /DESIGN = id cond . * I get the same F-test for COND in this analysis; so in the one-way repeated measures design, at least, it does not appear to be necessary to set ID as a random factor . * ------------ . * MISSING DATA . * ------------ . * If you use the usual approach to repeated measures ANOVA * (i.e., WIDE file and GLM REP MEASURES), any missing data * causes the entire case to be excluded from the analysis. * But if you use the LONG file and GLM UNIANOVA approach, * you can retain whatever data points are available for each person. * Create some missing data in variable DV, and re-run UNIANOVA to illustrate. if (id=1) and (cond=1) dv = 99. if (id=5) and (cond=2) dv = 99. if (id=8) and (cond=3) dv = 99. exe. UNIANOVA dv BY id cond /RANDOM = id /METHOD = SSTYPE(3) /INTERCEPT = INCLUDE /EMMEANS = TABLES(cond) /CRITERIA = ALPHA(.05) /DESIGN = id cond . * UNIANOVA still used all available data; F-test now has df = 2 and 11 * instead of 2 and 14. With the usual approach (one row per subject), * any missing values cause the entire case to be excluded from the analysis. * Try with ID as a fixed factor . UNIANOVA dv BY id cond /METHOD = SSTYPE(3) /INTERCEPT = INCLUDE /EMMEANS = TABLES(cond) /CRITERIA = ALPHA(.05) /DESIGN = id cond . * Again, I get the same F-test. * ----------------- . * ADDING COVARIATES . * ----------------- . * If you use the LONG file format (multiple rows per person) and GLM, * any baseline (or constant) covariates must be repeated on every row * for that person. If the covariate is time-dependent, you must record * the appropriate value on each row. * ----------------------------- . * ERROR TERMS MUST BE SPECIFIED . * ----------------------------- . * Using the LONG file format and UNIANOVA is more flexible than * GLM REPEATED MEASURES, but that flexibility comes at a price. * The price is that you have to specifiy ALL of the error terms to * be included in the model--actually, all but the last error term, * which will be the residual. * If you do not specify all of the error terms (except the last), * SPSS will use a pooled error term, which is most likely not * what you want to do. * For example, the following syntax is for a mixed-design ANOVA * with A as a between-Ss factor, and B and C within-Ss. Each * subject had 6 rows of data, one for each of the 6 B*C combinations. * The dependent variable was Y. *UNIANOVA y BY subj a b c /RANDOM = subj /METHOD = SSTYPE(3) /INTERCEPT = INCLUDE /CRITERIA = ALPHA(.05) /print = etasq /plot = resid /DESIGN = a subj(a) b b*a b*subj(a) c c*a c*subj(a) b*c b*c*a . * The notation "subj(a)" means "subjects nested within A". * The final error term, which I've omitted is: b*c*subj(a) . * This will show up as the residual, and will be used appropriately. * ================================================================== .