/************************************* * Repeated measures * * *************************************/ /* Edps/Soc 584 Psych 594 C.j.Anderson Data Timm who got is from Cochran & Cox Observations consitute a repeated measures design with two within subjects factors, which we are ignoring here. Response variableis the speed of calculation */ options nocenter; proc iml; * Module to compute sample statistics of a (n x p) data matrix; start stats(X,n,Xbar,W,S); n=nrow(X); one=j(n,1); Xbar = X`*one/n; XbarM = one*Xbar`; W=(X - XbarM)`*(X - XbarM); S= W/(N-1); finish stats; * A Module that computes Hottelings T^2 for one sample tests; start Tsq(X,muo,Ts,pvalue); n=nrow(X); one=j(n,1); Xbar = X`*one/n; XbarM = one*Xbar`; S=(X - XbarM)`*(X - XbarM)/(n-1); Ts=n*(xbar-muo)`*inv(S)*(xbar-muo); p=ncol(X); dfden=n-p; F=(n-p)/((n-1)*p)*Ts; pvalue = 1 - cdf('F',F,p,dfden); finish Tsq; X={ 30 21 21 14, 22 13 22 5, 29 13 18 17, 12 7 16 14, 23 24 23 8}; C1={1 -1 0 0, 0 1 -1 0, 0 0 1 -1}; C2={1 0 0 -1, 0 1 0 -1, 0 0 1 -1}; muo={0, 0, 0}; X1 = X*C1`; run stats(X1,n1,Xbar1,W1,S1); run Tsq(X1,muo,Tsq1,pvalue1); X2 = X*C2`; run stats(X2,n2,Xbar2,W2,S2); run Tsq(X2,muo,Tsq2,pvalue2); print 'Data matrix (5 subjects x 4 variables) = ', X, 'Using C1: ' C1, 'X*C1` =' X1, 'mean of C1*X1 = ' Xbar1, 'T^2 for C1*mu=0 ----> ' Tsq1 ' with p-value = ' pvalue1,, 'Using C2: ' C2, 'X*C2` =' X2, 'mean of C2*X2 = ' Xbar2, 'T^2 for C2*mu=0 ----> ' Tsq2 ' with p-value = ' pvalue2; quit; data calculator; input case x design; datalines; 1 30 1 2 22 1 3 29 1 4 12 1 5 23 1 1 21 2 2 13 2 3 13 2 4 7 2 5 24 2 1 21 3 2 22 3 3 18 3 4 16 3 5 23 3 1 14 4 2 5 4 3 17 4 4 14 4 5 8 4 ; proc mixed data=calculator covtest method=ml; class case design; model x = design / solution; random int /subject=case ; title 'Repeated Measured ANOVA as Null HLM'; run; proc sort data=calculator; by design; proc means noprint ; by design; var x; output out=xmeans mean=xbar; run; data toplot; set calculator xmeans; if _TYPE_=0 then do; x=xbar; case=0; end; run; goptions reset=(axis, legend, pattern, symbol, title, footnote) norotate hpos=0 vpos=0 htext=2.5 ftext=swiss ctext= target= gaccess= gsfmode= colors= csymbol= ; goptions device=WIN ctext=black graphrc interpol=none; axis1 color=black width=2.0 label=(angle=90 'Speed') ; axis2 color=black width=2.0 label=('Calculator Design') ; symbol1 value=square color=black i=none ; symbol2 value=dot color=red i=join; symbol3 value=dot color=green i=join; symbol4 value=dot color=blue i=join; symbol5 value=dot color=orange i=join; symbol6 value=dot color=brown i=join; legend1 position=(top center outside) frame cshadow=lgtgrey value=('Mean' '1' '2' '3' '4' '5') label=('Case'); proc gplot data=toplot; plot x*design=case / haxis=axis2 vaxis=axis1 legend=legend1; run;