MACRO chisqrbc rowi coli dist; reps r. # # Macro to perform approximate randomization for the chi-square # test of independence in a 2-way table of r rows and c columns. # The rows of the worksheet are the cases. Categorical values, which # may be text, in rowi and coli place this case into the appropriate row and column # of the 2-way table. # Copyright 2005 Robert L. Raymond University of St Thomas. Free use for # teaching and noncommercial research - retain this notice in this and # derivative works. MCONSTANT r grand nrow ncol i j k chisq MCOLUMN rowi coli dist rv rtot cv ctot xptd colperm temp1 DEFAULT r = 100 NOECHO BRIEF 0 TALLY rowi coli; STORE rv rtot cv ctot. SUM rtot grand N rtot nrow N ctot ncol DO i = 1:nrow DO j = 1:ncol SUBT 1 i k MULT k ncol k ADD j k k LET xptd(k) = rtot(i)*ctot(j) ENDDO ENDDO DIVIDE xptd grand xptd DO i = 1:r SAMPLE grand coli colperm STATS; BY rowi colperm; COUNT temp1. SUBT xptd temp1 temp1 MULT temp1 temp1 temp1 DIVIDE temp1 xptd temp1 SUM temp1 chisq LET dist(i) = chisq ENDDO SORT dist dist HISTOGRAM dist; TITLE 'Approximately Randomized Chi-Square'. BRIEF 2 ECHO ENDMACRO