ONEWAY with summarydata1
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 | * ONEWAY ANOVA with summary data (I): only one dataset. * Summary (aggregated) dataset (replace by your own data) Only one variable can analysed *. data list list/groups(A8) n(F5.0) mean(f8.1) sd(f8.3). begin data Control 10 62.8 6.9730 Respir 10 70.2 6.2147 Metabol 10 79.4 6.2397 Mixed 10 80.2 6.1065 end data. set mxloop=30000. matrix. * Import data *. get names/var=groups. get n/var=n. get mean/var=mean. get sd/var=sd. * General purposes 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 available". 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 /outfile=*. MSAVE sd /TYPE=STDDEV /fnames=group /factor=group. MSAVE n /TYPE=N /fnames=group /factor=group. print /title='Matrix data saved to current data file'. end matrix. ************ ANOVA with matrix data as input ***************** * If Bartlett (or Hartley, Cochran) test was non significant *. ONEWAY depvar BY group /STATISTICS=DESCRIPTIVES /POSTHOC=TUKEY /MATRIX=IN(*). * If Bartlett (or Hartley, Cochran) test was significant *. ONEWAY depvar BY group /STATISTICS=DESCRIPTIVES WELCH /POSTHOC=T2 /MATRIX=IN(*). *************************************************************** * Original data (for comparison purposes)*. data list free/group(f8.0) glucose(f8.0). begin data 1 51 1 56 1 58 1 60 1 62 1 63 1 65 1 68 1 72 1 73 2 60 2 65 2 66 2 68 2 68 2 69 2 73 2 75 2 78 2 80 3 69 3 73 3 74 3 78 3 79 3 79 3 82 3 85 3 87 3 88 4 70 4 75 4 76 4 77 4 79 4 80 4 82 4 86 4 88 4 89 end data. VAR LABEL group 'AcType' /glucose 'Glucose levels'. VALUE LABELS group 1 'Control' 2 'Respir' 3 'Metabol' 4'Mixed'. ONEWAY glucose BY group /STATISTICS=DESCRIPTIVES HOMOGENEITY WELCH /POSTHOC=TUKEY T2. * Differences: with summary dataset, Levene test is replaced by Cochran's, Hartley's & Bartlett's test and min/max values are missing in descriptives. * Extra statistics supplied by MATRIX code: - Altman's 95%CI for means (narrower) - Individual and within-groups cv(%). References: * Bartlett's test: * - Armitage and Berry (1987) "Statistical Methods in Medical Research", p 209. * Altman's 95%CI for means: * - Altman (1991) "Practical Statistics for Medical Research", p 209-210. |
Related pages
...