* ================================================================== . * File: varcomp_examples.SPS . * Date: 3-Aug-2004 . * Author: Bruce Weaver, weaverb@mcmaster.ca . * Notes: Use VARCOMP on LONG file to get variance components . * ================================================================== . * Example 1: Two factor design with repeated measures on both. * Generate random data file with an input program . set seed = 200425. new file. input program. loop #i = 1 to 10. - compute ID = $casenum. - compute grp = ID > 5. - compute o1.d1 = rnd(UNIFORM(4)) + 1. - compute o1.d5 = rnd(UNIFORM(4)) + 1. - compute o2.d1 = rnd(UNIFORM(4)) + 1. - compute o2.d5 = rnd(UNIFORM(4)) + 1. - compute o3.d1 = rnd(UNIFORM(4)) + 1. - compute o3.d5 = rnd(UNIFORM(4)) + 1. - end case. end loop. end file. end input program. exe. format id grp o1.d1 to o3.d5 (f2.0). var lab grp 'Group' o1.d1 'Observer 1, day 1' o1.d5 'Observer 1, day 5' o2.d1 'Observer 2, day 1' o2.d5 'Observer 2, day 5' o3.d1 'Observer 3, day 1' o3.d5 'Observer 3, day 5' . * Use GLM Repeated Measures on WIDE file . * Ignore between-Ss variable GRP in this analysis. * The following syntax was generated via Analyze-->GLM-->Repeated Measures. GLM o1.d1 o1.d5 o2.d1 o2.d5 o3.d1 o3.d5 /WSFACTOR = obs 3 Polynomial day 2 Polynomial /METHOD = SSTYPE(3) /PLOT = PROFILE( obs*day ) /CRITERIA = ALPHA(.05) /WSDESIGN = obs day obs*day . * Now restructure file to LONG format (i.e., one row per observation) . * The following syntax was pasted from the Data Restructure wizard, * which is entered by clicking on Data-->Restructure (when the data * window is active). VARSTOCASES /MAKE score FROM o1.d1 o1.d5 o2.d1 o2.d5 o3.d1 o3.d5 /INDEX = obs(3) day(2) /KEEP = id grp /NULL = KEEP. recode day (2=5) (else = copy). exe. * The data file now has one row per OBSERVATION, so several rows per ID. * Therefore, we must now use Analyze-->GLM-->UNIVARIATE to perform the analysis. * The following syntax was generated from that dialog. * For MODEL, I left it as "full factorial", then modifed the /DESIGN line * appropriately in the syntax editor. * Note that the final error term, obs*day*ID, is omitted from the /DESIGN line. * If it is included, SPSS computes a residual SS that is equal to 0, * and then no marginal means are computed, etc. UNIANOVA score BY obs day ID /RANDOM = ID /METHOD = SSTYPE(3) /INTERCEPT = INCLUDE /PLOT = PROFILE( obs*day ) /CRITERIA = ALPHA(.05) /DESIGN = ID obs obs*ID day day*ID obs*day . * With the final error term omitted, this analysis yields the same * F-tests as GLM Rep Measures we used earlier. * Now use Analyze-->GLM-->Variance Components to get the variance components. * Variables for which you want a variance component must be called RANDOM variables. means score /cells = var. * The variance of the scores = 1.84. * The variance components should sum to roughly this same amount. VARCOMP score BY id obs day /RANDOM = id obs day /METHOD = SSTYPE (1) /DESIGN = ID obs obs*ID day day*ID obs*day /INTERCEPT = INCLUDE . * Same thing but with the default method, i.e., * MINQUE (1) [minimum norm quadratic unbiased estimate] . VARCOMP score BY id obs day /RANDOM = id obs day /METHOD = MINQUE (1) /DESIGN = ID obs obs*ID day day*ID obs*day /INTERCEPT = INCLUDE . * ----------------------------------------- . * Example 2: Add one between-groups factor . * ----------------------------------------- . * ID is now nested within group. * In SPSS syntax, this nesting is indicated as follows: ID(GRP) . * Note the changes to the /DESIGN line. The final error term, * obs*day*id(grp), is omitted, and will appear as the residual. UNIANOVA score BY ID grp obs day /RANDOM = ID /METHOD = SSTYPE(3) /INTERCEPT = INCLUDE /PLOT = PROFILE( obs*day ) /CRITERIA = ALPHA(.05) /DESIGN = grp ID(grp) obs obs*grp obs*ID(grp) day day*grp day*ID(grp) obs*day obs*day*grp . * Variance components with Method = ANOVA(1). VARCOMP score BY id grp obs day /RANDOM = id obs day /METHOD = SSTYPE (1) /DESIGN = grp ID(grp) obs obs*grp obs*ID(grp) day day*grp day*ID(grp) obs*day obs*day*grp /INTERCEPT = INCLUDE . * Same thing but with the default method, i.e., * MINQUE (1) [minimum norm quadratic unbiased estimate] . VARCOMP score BY id grp obs day /RANDOM = id obs day /METHOD = MINQUE (1) /DESIGN = grp ID(grp) obs obs*grp obs*ID(grp) day day*grp day*ID(grp) obs*day obs*day*grp /INTERCEPT = INCLUDE . * ================================================================== .