* THIS MACRO CONDUCTS AN APPROXIMATE RANDOMIATION TEST-EQUIVALENT OF */. /* A ONEWAY ANOVA, USING F AS THE TEST STATISTIC. THE SYNTAX IS */. /* RANDGRP y = dv/grp = iv/nperm = z, WHERE DV IS THE DEPENDENT */. /* VARIABLE, IV IS THE INDEPENDENT VARIABLE THAT CODES GROUP, AND */. /* Z IS THE NUMBER OF RANDOMIZATIONS DESIRED */. DEFINE RANDGRP (y = !charend('/')/grp = !charend('/')/nperm = !charend('/')). SET MXLOOPS = 10000001. preserve. set length = none. set seed = random. MATRIX. get dat/variables = !grp !y/MISSING = OMIT. compute n = nrow(dat). compute y = dat(:,2). compute grp = dat(:,1). compute v=design(grp). compute my = csum(y)/nrow(y). compute ngrp = t(csum(v)). compute gsum = t(v)*y. compute gps=nrow(ngrp). loop i = 1 to ncol(v). loop j = 1 to n. do if v(j,i) = 1. compute dat(j,1)=i. end if. end loop. end loop. compute mns = gsum&/ngrp. compute mns = {ngrp,mns}. print mns/title = " Group Statistics"/clabels = "n" "Mean"/format F12.4. compute results=uniform(!nperm,1). compute pos=0. compute sxs=(cssq(dat)). compute sxs=sxs(1,2). compute sts=csum(dat). compute sts=(sts(1,2)*sts(1,2))/n. loop perm = 1 to !nperm. loop ce = 1 to n. do if perm > 1. compute k = trunc(uniform(1,1)*(n-ce+1))+ce. compute temp =dat(ce,2). compute dat(ce,2) = dat(k,2). compute dat(k,2) = temp. end if. end loop. compute ttl=0/ngrp. loop ce=1 to n. compute ttl(dat(ce,1),1)=ttl(dat(ce,1),1)+dat(ce,2). end loop. compute test = 0. loop ce = 1 to nrow(ngrp). compute test = test+((ttl(ce,1)*ttl(ce,1))/ngrp(ce,1)). end loop. compute results(perm,1)=test. end loop. loop k = 1 to !nperm. do if results(k,1) >= results(1,1). compute pos=pos+1. end if. end loop. compute results = ((results-sts)/(gps-1))/((sxs-results)/(n-gps)). compute p = {abs(results(1,1)),(pos/!nperm)}. print p/title = "Results of Approximate Randomization Test"/clabels = " F" "p-value"/format F12.4. print !nperm/title = "Number of randomizations requested". save results/outfile = 'permdisf.sav'/variables perm. END MATRIX. RESTORE. !END DEFINE.