# Kruskal Wallis and Mood's median

#### StatsClue

##### New Member
Would appreciate some perspective on the following:

Is the Mood's median test now rarely used?

I am comparing right-skewed distributions (3 groups; 350 obs. each). The Kruskal-Wallis test only seems to say that there is a difference among the three but does not specifiy where the difference lies. For writing my paper, is it a good idea to do the Kruskal Wallis test first and follow it up with a Mood's median table that will show the frequencies above and below the overall median so that a sense of where the difference lies can be had? Thanks.

#### gianmarco

##### TS Contributor
Hi!
Any stat pack routinely provides a post-hoc test to pinpoint where the significant difference is. Some software performs a pair-wise Mann-Whitney U test between samples.
I think that you could find many earlier thread on this topic here in the Forum.

Further, I believe that those approaches supersede Mood's median test.

Hope this helps,
regards
Gm

#### StatsClue

##### New Member
Thanks a lot. I don't think SAS does. Couldn't find a post-hoc test for Kruskal-Wallis, like there exists for ANOVA (/tukey). Read up some and the suggestion seemed to be to compare each pair at a time to know where the difference lay (would of course be very difficult if there were a large number of groups). Also, that multiple-comparisons had to be accounted for using bonferroni technique that I think would tell you what signficance level to use to decide if the pairwise comparisons were signficantly different. No idea how to go about the bonferroni techique.

#### gianmarco

##### TS Contributor
p.s.

I guess that R can easily handle the test, but I have never used it to date.

#### hlsmith

##### Omega Contributor
Can think of two options:

You can multiply all of the p-values from the pairwise comparisons by the number of pairwise tests to get the bonferroni corrected p-values.

or use the following code

Code:
ODS OUTPUT WilcoxonScores=wlx(drop=variable);
ODS EXCLUDE wilcoxonScores;

PROC NPAR1WAY data=full wilcoxon;
CLASS year; VAR q1;
TITLE1 'Nonparametric Analysis: Kruskall Wallis Test';
run;

PROC PRINT DATA=wlx NOObs ;
run;

* macro var k == number of groups;

DATA _null_ ; SET wlx nobs=nobs; CALL SYMPUT("k",LEFT(nobs)); run;

%put &k.;

PROC TRANSPOSE DATA =wlx OUT=cnts(drop=_name_ _label_) prefix=_n; var n;
ID class; run;
PROC TRANSPOSE DATA =wlx OUT=mns(drop=_name_ _label_) prefix=_mn; var
meanscore; ID class; run;

proc print data=cnts; RUN;
proc print data=mns; RUN;

%LET alpha=.05; * familywise pvalue ;

/*Below, I just substituted Z for the number that made the critical value
equal to the absolute difference, then looked that number up on a normal
distribution table. This number provides the unadjusted p-value that you
compare with the Bonferroni alpha level of significance. */

/*Next you can multiply the unadjusted p-value by k, to determine the Bonferrroni
adjusted p-value for the wilcoxon multitest*/
DATA results; SET cnts; SET mns; DROP nn _n1-_n&k. _mn1-_mn&k.;
LENGTH reject $2; RETAIN reject ' '; LABEL compare='Critical Value' abs_diff='Absolute Difference in Mean Ranks'; c= ((&k.*(&k.-1))/2); * number of pairwise tests; z = PROBIT( (1- ((&alpha./2)/ c) ) ); * multiplier ; nn=SUM(of _n1-_n&k.); * total number of observations ; ARRAY nc{&k.} _n1 - _n&k.; ARRAY mn{&k.} _mn1 - _mn&k.; DO i = 1 to (&k.-1); DO j = (i+1) TO &k.; sc1 = mn{i}; sc2 = mn{j}; ABS_diff = abs(sc1 - sc2); compare = z * SQRT( nn*(nn+1)/12 * ((1/nc{i}) + (1/nc{j}))); IF abs_diff > compare then reject='**'; * the ** marker is to denote any significant differences ; OUTPUT results; reject=' '; * reset marker to missing ; END; END; RUN; proc print data=results NOobs label; var i j sc1 sc2 ABS_diff compare reject z; FORMAT abs_diff 6.3 compare 6.2; run; #### jrai ##### New Member You can also use %DUNN macro available online. It applies Bonferroni correction to the non-parametric tests. #### hlsmith ##### Omega Contributor If you are interested in this MACRO like I was, it is available at the following URL along with 2 other familywise correction MACROS: %DUNN MACRO available under June 2004, Simultaneous Nonparametric Inference in a One-Way Layout Using the SAS System (251 Kb zip file includes code) - Paul Juneau, Pfizer at http://www.misug.org/presentations.html #### StatsClue ##### New Member Hello, still trying to figure this out. One additional question: Can I add a fourth group here with only about a 100 observations for the comparison? i.e. the kruskal wallis will be done on 4 groups with n1=350, n2=350, n3=350, n4=100. Will the results be valid or do the number of obs. need to be about the same? THANKS A BUNCH. #### gianmarco ##### TS Contributor KW can be performed on samples of different size. The same applies for Dunn's posthoc test. Gm #### StatsClue ##### New Member Thank you gianmarco. I can't understand the marco above or the DUNN marco at all (I'm not even sure what macro means). My really dumb question is what to substitute where in the code above (pasted below). I only substituted the dataset name, class and variable name (starting 'statsclue..' here). The initial part seemed to run fine but the latter part was botched. I'm not sure how to find out the p-value of interest. Code: ODS OUTPUT WilcoxonScores=wlx(drop=variable); ODS EXCLUDE wilcoxonScores; PROC NPAR1WAY data=STATSCLUE wilcoxon; CLASS STATSCLUECLASS; VAR STATSCLUEVARIABLE; TITLE1 'Nonparametric Analysis: Kruskall Wallis Test'; run; PROC PRINT DATA=wlx NOObs ; run; * macro var k == number of groups; DATA _null_ ; SET wlx nobs=nobs; CALL SYMPUT("k",LEFT(nobs)); run; /*Should I substitute 4 for k here?*/ %put &k.; PROC TRANSPOSE DATA =wlx OUT=cnts(drop=_name_ _label_) prefix=_n; var n; ID class; run; PROC TRANSPOSE DATA =wlx OUT=mns(drop=_name_ _label_) prefix=_mn; var meanscore; ID class; run; proc print data=cnts; RUN; proc print data=mns; RUN; %LET alpha=.05; * familywise pvalue ; /*Below, I just substituted Z for the number that made the critical value equal to the absolute difference, then looked that number up on a normal distribution table. This number provides the unadjusted p-value that you compare with the Bonferroni alpha level of significance. */ /*Next you can multiply the unadjusted p-value by k, to determine the Bonferrroni adjusted p-value for the wilcoxon multitest*/ DATA results; SET cnts; SET mns; DROP nn _n1-_n&k. _mn1-_mn&k.; LENGTH reject$2; RETAIN reject ' ';
LABEL compare='Critical Value' abs_diff='Absolute Difference in Mean
Ranks';
c= ((&k.*(&k.-1))/2); * number of pairwise tests;
z = PROBIT( (1- ((&alpha./2)/ c) ) ); * multiplier ;
nn=SUM(of _n1-_n&k.); * total number of observations ;
ARRAY nc{&k.} _n1 - _n&k.;
ARRAY mn{&k.} _mn1 - _mn&k.;
DO i = 1 to (&k.-1);
DO j = (i+1) TO &k.;
sc1 = mn{i}; sc2 = mn{j};
ABS_diff = abs(sc1 - sc2);
compare = z * SQRT( nn*(nn+1)/12 * ((1/nc{i}) + (1/nc{j})));
IF abs_diff > compare then reject='**'; * the ** marker is to denote
any significant differences ;
OUTPUT results;
reject=' '; * reset marker to missing ;
END;

END;
RUN;

proc print data=results NOobs label;
var i j sc1 sc2 ABS_diff compare reject z;
FORMAT abs_diff 6.3 compare 6.2;
run;
PS: I realize the question's dumb. Will try to comprehend this more and refine my question. Any help though would be appreciated.

#### gianmarco

##### TS Contributor
Hi!
I am not so familiar with that macro. For what program is it for?

Have you tried R, or some other program?

Gm