ONEWAY with summarydataI2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | * ONEWAY ANOVA with summary data (II): several datasets at the same time. * MATRIX...END MATRIX recognizes SPLIT groups only in batch mode (INCLUDE). * (A) Sample datasets * data list list/testnum(F4.0) groups(A8) n(F5.0) mean(F8.1) sd(F8.3). begin data 1 Control 10 62.8 6.9730 1 Respir 10 70.2 6.2147 1 Metabol 10 79.4 6.2397 1 Mixed 10 80.2 6.1065 2 Control 15 72.8 7.7703 2 Respir 15 80.4 7.3174 2 Metabol 15 89.4 7.4379 2 Mixed 15 90.2 8.1056 end data. * (B) Copy & Save the following syntax as "C:\\Temp\\SummaryANOVA.sps". ******************** SYNTAX STARTS HERE *******************. matrix. * Import data *. get varnum /var=testnum. get names/var=groups. get n/var=n. get mean/var=mean. get sd/var=sd. print /title="-------------------------------------------". print varnum(1) /format="f8.0" /title="Split by:" /clabel="Nr.". /rlabel="Variable" * General calculations *. compute k=nrow(n). compute totaln=msum(n). compute var=sd&**2. compute dfwithin=totaln-k. compute poolvar=msum((n-1)&*var)/dfwithin. * Homogeneity of variances tests *. do if cmax(n)=cmin(n). print /title="Balanced design. Hartley's & Cochran's tests are possible". compute cochran=cmax(var)/msum(var). compute fmax=cmax(var)/cmin(var). print {cmax(var),cmin(var),fmax} /title="Hartley's Fmax test (check with tabulated critical values)" /format="f8.3" /clabels="Max S^2","Min S^2","H value". print cochran /title="Cochran's test (check with tabulated critical values)" /format="f8.3" /clabel="C value". print (n(1)-1) /title="DF for all groups" /format="f8.0". end if. print k /title="Number of groups (K)" /format="f8.0". compute x2=dfwithin*ln(poolvar)-msum((n-1)&*ln(var)). compute cc=1+(msum(1/(n-1))-1/dfwithin)/(3*(k-1)). compute chi2=x2/cc. compute chisig=1-chicdf(chi2,k-1). print {chi2,chisig} /title="Bartlett's Homogeneity of Variances Test (df=K-1)" /format="f8.3" /clabels="Chi^2","Sig.". * Sample & Total descriptives *. compute gmean=(msum(n&*mean))/totaln. compute totsd=sqrt((msum((n-1)&*var+n&*(mean&**2))-(gmean&**2)*totaln)/(totaln-1)). compute eem=sd&/sqrt(n). compute toteem=totsd/sqrt(msum(n)). compute samplecv=100*sd/mean. compute totalcv=100*totsd/gmean. * Altman's 95%CI for means (using MSwithin & DFwithin instead of data from each sample) *. loop tvalue95=1960 to 12706. compute t95=tvalue95/1000. compute onetail=1-tcdf(t95,dfwithin). do if abs(onetail-0.025) lt 0.00005. break. end if. end loop. compute low95=mean-t95*sqrt(poolvar/n). compute upp95=mean+t95*sqrt(poolvar/n). compute lowgmean=gmean-t95*sqrt(poolvar/totaln). compute uppgmean=gmean+t95*sqrt(poolvar/totaln). * Report *. compute names={names;'Total'}. print {n,mean,sd,samplecv,eem,low95,upp95;totaln,gmean,totsd,totalcv,toteem,lowgmean,uppgmean} /title="Descriptives: 95%CI for means (*) " /clabels='N','Mean','Sd','cv(%)','sem','Lower','Upper' /rnames=names /format='F7.2'. * Within groups (residual) CV *. compute cvar=100*sqrt(poolvar)/gmean. print cvar /title="Within-groups coefficient of variation (*)" /format="F5.2" /rlabels="CV(%)=". print /title="(*) Altman's 95%CI and Within-groups CV require homogeneous variances". * Writing data in matrix data format *. compute group=T({1:k}). MSAVE mean /TYPE=MEAN /fnames=group /factor=group /variable=depvar /snames=testnum /split=varnum /outfile=*. MSAVE sd /TYPE=STDDEV /fnames=group /factor=group /variable=depvar /snames=testnum /split=varnum /outfile=*. MSAVE n /TYPE=N /fnames=group /factor=group /variable=depvar /snames=testnum /split=varnum /outfile=*. print /title='Matrix data saved to current data file'. end matrix. **************************** END OF SYNTAX **************************. * (C) Now, we split the file by "testnum" and run the syntax. set mxloop=30000. split file layered by testnum. include "C:\\Temp\\SummaryANOVA.sps". * The last part is to perform a ONEWAY ANOVA for every variable in the dataset. * If ONEWAY with MATRIX DATA as input & SPLIT FILE worked OK, this would be the way of computing the ANOVA for both variables at the same time (as a matter of fact, split file IS activated). * ONEWAY depvar BY group /STATISTICS=DESCRIPTIVES WELCH /POSTHOC=TUKEY T2 /MATRIX=IN(*). *********************************************. * As it doesn't work (SPSS bug?), the solution is a MACRO *. (D) MACRO DEFINITION *. DEFINE !oneway (!POSITIONAL !TOKENS(1)). !DO !cnt=1 !TO !1. TEMPORARY. SELECT IF(testnum = !cnt). * You can replace the POSTHOC tests by your favorites ones. ONEWAY depvar BY group /STATISTICS=DESCRIPTIVES WELCH /POSTHOC=TUKEY T2 /MATRIX=IN(*). !DOEND. !ENDDEFINE. (E) MACRO CALL *. !oneway 2. |
Related pages
...