Programming the statistical procedures from SAS

Compare two medians

Accepted Solution Solved
Reply
Trusted Advisor
Posts: 1,659
Accepted Solution

Compare two medians

Is there a test in SAS that compares two medians? I am looking for the equivalent of PROC TTEST, but with medians instead of means.

Thanks.


Accepted Solutions
Solution
‎07-06-2017 08:55 AM
SAS Super FREQ
Posts: 3,542

Re: Compare two medians

I'm not an expert, but I believe that the Mann-Whitney (aka, Wilcoxon-Mann-Whitney or just Wilcoxon) test is generally used as an alternative to a t test when the data are not normally distributed. The Mann-Whitney test is commonly regarded as a test of population medians, but this is technically only true if the two populations have the same shape and one is a "translation" (or shift) of the other. If the populations have different scales and shape, the M-W test will detect that as well, which tends to muddy the results.

You might want to create box plots of the two groups. If the boxes are approximately the same size and shape, but one is offset from the other, then an M-W test would be a way to test whether the medians are different.

For an introduction to nonparametric tests, including how to perform a M-W test by using PROC NPAR1WAY, see http://analytics.ncsu.edu/sesug/2004/TU04-Pappas.pdf

View solution in original post


All Replies
Respected Advisor
Posts: 4,745

Re: Compare two medians

Look at the MEDIAN test available in NPAR1WAY.

PG

PG
Trusted Advisor
Posts: 1,659

Re: Compare two medians

It was always my understanding that the median test in PROC NPAR1WAY was a non-parametric test of means, not of medians.

Respected Advisor
Posts: 4,745

Re: Compare two medians

The mean is never mentioned in the definition of the test. My experience is that this test isn't very powerful which might explain why it is so rarely used. - PG

PG
PROC Star
Posts: 7,416

Re: Compare two medians

Trusted Advisor
Posts: 1,659

Re: Compare two medians

Arthur Tabachneck wrote:

You can also use proc freq.  Take a look at http://support.sas.com/documentation/cdl/en/statug/63033/HTML/default/viewer.htm#statug_intronpar_se...

I don't see the word "median" anywhere in the PROC FREQ documentation.

PROC Star
Posts: 7,416

Re: Compare two medians

: I'll have to leave it to , or another statistician to provide the correct answer but, the following is in the documentation:

SAS/STAT software provides the following nonparametric tests for comparing the locations of two related

samples:

  Wilcoxon signed rank test

  sign test

  McNemar’s test

The first two tests are available in the UNIVARIATE procedure, and the last test is available in the FREQ

procedure. When you perform these tests, your data should consist of pairs of measurements for a random

sample from a single population. For example, suppose your data consist of SAT scores for students before

Tests for k Samples F 281

and after attending a course on how to prepare for the SAT. The pairs of measurements are the scores before

and after the course, and the students should be a random sample of students who attended the course. Your

goal in analysis is to decide whether the median change in scores is significantly different from zero.

Trusted Advisor
Posts: 1,659

Re: Compare two medians

Arthur Tabachneck wrote:

"When you perform these tests, your data should consist of pairs of measurements for a random

sample from a single population."

Okay, that does not describe my situation.

Respected Advisor
Posts: 2,655

Re: Compare two medians

Then PG's answer at #1 is what you need--the median test in PROC NPAR1WAY.

Steve Denham


Solution
‎07-06-2017 08:55 AM
SAS Super FREQ
Posts: 3,542

Re: Compare two medians

I'm not an expert, but I believe that the Mann-Whitney (aka, Wilcoxon-Mann-Whitney or just Wilcoxon) test is generally used as an alternative to a t test when the data are not normally distributed. The Mann-Whitney test is commonly regarded as a test of population medians, but this is technically only true if the two populations have the same shape and one is a "translation" (or shift) of the other. If the populations have different scales and shape, the M-W test will detect that as well, which tends to muddy the results.

You might want to create box plots of the two groups. If the boxes are approximately the same size and shape, but one is offset from the other, then an M-W test would be a way to test whether the medians are different.

For an introduction to nonparametric tests, including how to perform a M-W test by using PROC NPAR1WAY, see http://analytics.ncsu.edu/sesug/2004/TU04-Pappas.pdf

SAS Employee
Posts: 6

Re: Compare two medians

You can use PROC QUANTREG. Suppose you have two variables, y1 and y2, that potentially have different medians. Create a new variable y that is just y1 stacked on top of y2, and create a dummy variable x that has a value of 0 if an observation is from y1 and a value of 1 if an observation is from y2. Now you can use QUANTREG to estimate the median conditional on the value of x. The TEST statement performs a WALD test of whether the effect of x is significantly different from 0.

Here is a sample program that demonstrates:

data one;

   call streaminit(736283);

   do i = 1 to 100;

      if i<51 then y=rand('NORMAL',0,1);

      if i<51 then x=0;

      if i>=51 then y=rand('NORMAL',1,1);

      if i>=51 then x=1;

      output;

   end;

run;

proc quantreg data=one;

   class x;

   model y=x;

   test x;

run;

The resulting Wald test statistic is 13.2403, the p-value is 0.0003.

Trusted Advisor
Posts: 1,659

Re: Compare two medians

Thanks, Allen. That looks like a reasonable approach. Do you have any references on the Wald test? I don't really find much in SAS docs for PROC QUANTREG about the Wald test.

SAS Employee
Posts: 6

Re: Compare two medians

The mathematical details of the Wald test are provided at:

http://support.sas.com/documentation/cdl/en/statug/65328/HTML/default/viewer.htm#statug_qreg_syntax1...

You can also perform a likelihood ratio test by specifying the LR option in the TEST statement; the mathematical details are provided on this same page.

Trusted Advisor
Posts: 1,659

Re: Compare two medians

AllenMcDowell wrote:

The mathematical details of the Wald test are provided at:

http://support.sas.com/documentation/cdl/en/statug/65328/HTML/default/viewer.htm#statug_qreg_syntax1...

You can also perform a likelihood ratio test by specifying the LR option in the TEST statement; the mathematical details are provided on this same page.

With all due respect, there are no mathematical details of the Wald test at this link.

SAS Employee
Posts: 6

Re: Compare two medians

Sorry, wrong link. try this one:

http://support.sas.com/documentation/cdl/en/statug/65328/HTML/default/viewer.htm#statug_qreg_details...

or look at the Details section and select the "Linear Test" entry.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 25 replies
  • 7665 views
  • 11 likes
  • 8 in conversation