*The following example includes synthetic data for a 3 (AGE) x 3 (Diet) between-subjects structure crossed with a 3 (time) x 2 (rater) within-subjects structure. *The command 'Group=AGE + 3*(diet -1)' calculates a variable that numbers the groups from 1 to 9 and would need to be changed for other between-subjects structures; *The number of groups, number of trials, and number of between-subjects factors is declared in PROC IML; *The program is based on the general linear hypothesis CMR=0. See the comment following the FINISH command in regard to constructing the matrices C and R; options pagesize=65; data total; input diet age y11 y21 y31 y12 y22 y32; Group=AGE + 3*(diet -1); cards; 1 1 4 3 3 8 6 1 1 3 5 3 2 4 3 3 1 3 3 3 2 5 3 2 2 3 6 3 2 3 3 2 2 3 3 2 1 6 3 2 2 3 6 5 3 3 2 1 3 1 8 4 2 6 5 3 1 3 9 7 3 8 4 2 3 3 6 6 3 9 7 3 1 2 4 4 3 6 6 3 3 3 6 5 4 4 4 3 3 3 5 4 1 6 5 4 2 1 5 4 1 5 4 1 2 1 5 5 4 5 4 1 2 2 7 6 4 5 5 4 2 1 3 6 3 7 6 4 2 1 2 4 1 3 6 3 3 2 9 5 2 2 4 1 1 1 4 3 1 9 5 2 1 2 6 5 4 4 3 1 1 2 4 2 2 6 5 4 2 1 7 6 3 4 2 2 2 2 4 3 1 7 6 3 2 2 4 3 2 4 3 1 3 1 7 7 4 4 3 2 3 2 3 5 1 7 7 4 3 2 7 9 4 3 5 1 1 1 3 2 1 7 9 4 1 2 5 4 1 3 2 1 1 2 5 2 1 5 4 1 2 1 6 4 2 5 2 1 2 2 4 2 1 6 4 2 2 2 7 4 3 4 2 1 3 1 4 7 1 7 4 3 3 2 6 5 2 4 7 1 3 2 8 6 1 6 5 2 PROC SORT; BY AGE DIET; PROC PRINT; PROC IML; /****************************************************/ /* FORM VAR-COV BLOCK MATRIX AND VECTOR */ /* OF TRIAL MEANS */ /****************************************************/; USE TOTAL; /*-------------INITIALIZE------------------*/; G=9; /* NUMBER OF GROUPS */; L=6; /* NUMBER OF TRIALS */; M=2; /*NUMBER OF BETWEEN-SUBJECTS FACTORS*/; P=L; L=0; BSF=M; M=0; NW=0; DN = J(G,G,0); JK=G*P; NINV=J(G,G,0); RINV=J(G,1,0); DF=J(G,1,0); AA=J(G,1,0); VC=J(JK,JK,0); VCDNG=J(JK,JK,0); /*---------- VARCOV SUBROUTINE------------------------*/; START VARCOV; DO I=1 TO G; READ ALL WHERE (GROUP=I) INTO XN; NOBS=NROW(XN); DF(|I|)=NOBS-1; NI=1/NOBS; XN=XN(|1:NOBS,BSF+1:(P+BSF)|); SSCP=(XN`*(I(NOBS)-J(NOBS,NOBS,NI))*XN); VCV=SSCP/DF(|I|); TRMN=(XN(|+,|))/NOBS; DN(|I,I|)=NOBS; IF (I=1) THEN DO; N=NOBS;NW=NI; MEAN=TRMN;SMEAN=TRMN; WSVCV=NI*VCV; E=SSCP; END; ELSE DO; N=N+NOBS;NW=NW+NI; MEAN=MEAN||TRMN;SMEAN=SMEAN + TRMN; WSVCV=WSVCV + NI*VCV; E=E +SSCP; END; F=I*P-(P - 1); L=I*P; VC(|F:L,F:L|)=VCV; VCV=VCV/NOBS; VCDNG(|F:L,F:L|)=VCV; END; WAVCV = WSVCV/NW; SP = E/(N - G); FINISH; RUN VARCOV; /*------SUBROUTINE FOR WS TESTS-----*/; START WS_TEST; DENBHAT=0; ETA1=0;ETA2=0; DELTA=0; DEN_G=0; RR_G=0; B_G=0; DELTA_G=0; ETA_G=0; HETA=0; A_G=0; SSN = (INV(NW))*SMEAN*A*A`*SMEAN`;print SSN; DFN = NCOL(A); PRINT DFN; MSN=SSN/NCOL(A); PRINT MSN; SSD = (N-G)*(TRACE(A`*SP*A)); PRINT SSD; DFD = (N-G)*NCOL(A); PRINT DFD; MSD = SSD/DFD; PRINT MSD; F = SSN/(MSD*(NCOL(A))); PRINT F; DO I=1 TO G; NG=DN(|I,I|); F=I*P-(P - 1); L=I*P; VCG=VC(|F:L,F:L|); DEN_G=(NG-1)*TRACE(A`*VCG*A); AA(|I|)=TRACE(A`*VCG*A); A_G=AA(|I|); B_G=TRACE((A`*VCG*A)**2); RR_G=((NG-1)**2)/((NG+1)*(NG-2)); DELTA_G=RR_G*((NG-1)*(B_G)-(A_G**2)); ETA_G=(NG-1)*RR_G*((NG*(A_G**2))-2*B_G); IF I=1 THEN DO; DENBHAT=DEN_G; DELTA=DELTA_G; ETA1=ETA_G; END; ELSE DO; DELTA=DELTA + DELTA_G; DENBHAT=DENBHAT+DEN_G; ETA1=ETA1 + ETA_G; END; END; DO I= 1 TO G; DO J= 1 TO G; HETA= DF(|I|)*DF(|J|)*AA(|I|)*AA(|J|); IF (I=J) THEN HETA=0; ETA2=ETA2+HETA; END; END; ETA =ETA1 + ETA2; HTILDE = ETA/DELTA; PRINT HTILDE; IF HTILDE >= (N-G)*NCOL(A) THEN HTILDE = (N-G)*NCOL(A); PRINT HTILDE; BHAT=(N - G)*(TRACE(A`*WAVCV*A))/DENBHAT; PRINT BHAT; HP=((TRACE(A`*WAVCV*A))**2)/(TRACE((A`*WAVCV*A)**2)); HPTILDE=((N - G + 1)*HP-2)/(N - G - HP); IF HPTILDE >= NCOL(A) THEN HPTILDE = NCOL(A); PRINT HPTILDE; CV=BHAT*(FINV(.95,HPTILDE,HTILDE)); PRINT CV; FINISH; /*---------SUBROTINE FOR BETWEEN X WITHIN INTERACTIONS--------------*/; START BSWSTEST; GM=(C*(INV(C`*(INV(DN))*C))*C`)@(A*A`); SSN=MEAN*GM*MEAN`; PRINT SSN; DFN=NCOL(C)*NCOL(A); PRINT DFN; MSN=SSN/(NCOL(C)*NCOL(A)); PRINT MSN; F=(SSN/(NCOL(C)*NCOL(A)))/MSD; PRINT F; TT=DF#AA; SUM=TT(|+,|); CHAT=((N - G)*TRACE(GM*VCDNG))/((NCOL(C))*TT(|+,|)); PRINT CHAT; HPP=((TRACE(GM*VCDNG))**2)/(TRACE((GM*VCDNG)**2)); HPPTILDE=(NCOL(C))*((N-G+1)*HPP - 2*(NCOL(C)))/((N-G)*(NCOL(C))-HPP); IF HPPTILDE >= (NCOL(C))*NCOL(A) THEN HPPTILDE = (NCOL(C))*NCOL(A); PRINT HPPTILDE; CV=CHAT*(FINV(.95,HPPTILDE,HTILDE)); PRINT CV; FINISH; *In the following code c2 is a 2x1 contrast vector for comparing levels of the two-level factors rater. c3 is a 3 x 2 contrast matrix for comparing levels of three-level factors--diet, age, and time in this example. C and R are matrices in the general linear hypothesis CMR=0 where M is a matrix of means with rows defined by groups and columns defined by variables and 0 is a matrix of zeroes. C and R are computed by appropriate Kronecker products of c2, c3, and 3x1 and 2x1 vectors of ones. The matrices c2 and c3 and 3x1 and 2x1 vectors of ones would have to be changed to accomodate a new design; c3={1 0, 0 1 ,-1 -1}; *R is for TIME; R=j(2,1,1)@c3; CALL GSORTH(A,TT,LL,R); PRINT 'THE FOLLOWING RESULTS ARE FOR THE TIME FACTOR'; RUN WS_TEST ; *c is for AGE; C=j(3,1,1)@c3; PRINT 'THE FOLLOWING RESULTS FOR THE AGExTIME INTERACTION'; RUN BSWSTEST; *c is for DIET; C=c3@j(3,1,1); PRINT 'THE FOLLOWING RESULTS FOR THE DIETxTIME INTERACTION'; RUN BSWSTEST; *c is for DIET; C=c3@c3; PRINT 'THE FOLLOWING RESULTS FOR THE AGExDIETxTIME INTERACTION'; RUN BSWSTEST; c2={1 , -1}; *R is for RATER; R=C2@j(3,1,1); CALL GSORTH(A,TT,LL,R); PRINT 'THE FOLLOWING RESULTS ARE FOR THE RATER FACTOR'; RUN WS_TEST ; *c is for AGE; C=j(3,1,1)@c3; PRINT 'THE FOLLOWING RESULTS FOR THE AGExRATER INTERACTION'; RUN BSWSTEST; *c is for DIET; C=c3@j(3,1,1); PRINT 'THE FOLLOWING RESULTS FOR THE DIETxRATER INTERACTION'; RUN BSWSTEST; *c IS FOR AGE X DIET; C=c3@c3; PRINT 'THE FOLLOWING RESULTS FOR THE AGExDIETxRATER INTERACTION'; RUN BSWSTEST; *R is for TIMExRATER; R=C2@C3; CALL GSORTH(A,TT,LL,R); PRINT 'THE FOLLOWING RESULTS ARE FOR THE TIMExRATER INTERACTION'; RUN WS_TEST ; *c is for AGE; C=j(3,1,1)@c3; PRINT 'THE FOLLOWING RESULTS FOR THE AGExTIMExRATER INTERACTION'; RUN BSWSTEST; *c is for DIET; C=c3@j(3,1,1); PRINT 'THE FOLLOWING RESULTS FOR THE DIETxtIMExRATER INTERACTION'; RUN BSWSTEST; *c IS FOR AGE X DIET; C=c3@c3; PRINT 'THE FOLLOWING RESULTS FOR THE AGExDIETxTIMExRATER INTERACTION'; RUN BSWSTEST;