BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

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

25 REPLIES 25
PGStats
Opal | Level 21

Look at the MEDIAN test available in NPAR1WAY.

PG

PG
PaigeMiller
Diamond | Level 26

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

--
Paige Miller
PGStats
Opal | Level 21

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
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
art297
Opal | Level 21

: 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.

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
SteveDenham
Jade | Level 19

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

Steve Denham


Rick_SAS
SAS Super FREQ

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

AllenMcDowell
SAS Employee

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.

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
AllenMcDowell
SAS Employee

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.

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
AllenMcDowell
SAS Employee

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 25 replies
  • 23819 views
  • 14 likes
  • 8 in conversation