BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Rick_SAS
SAS Super FREQ

It's an intriguing idea, but if it were me I'd use the simpler NPAR1WAY procedure. To me, the simpler procedure has the advantage of more explicit assumtions and (often) more power than the general test. (And it's easier for me to understand what is being tested.) By way of an analogy, if I'm testing for the difference of means, I wouldn't use PROC GLM and the ESTIMATE statement when I could use PROC TTEST.

For example, rerun @AllenMcDowell's DATA step where the second mean is 0.5:

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

Now compare the QUANTREG and NPAR1WAY results. In this case the Wilcoxon two-sample test has a p-value of 0.0174,the MEDIAN test has a p-value of 0.047, and the QUANTREG Wald test has a p-value of 0.09:

proc npar1way data=one median wilcoxon;

class x;

var y;

run;

PaigeMiller
Diamond | Level 26

Rick Wicklin wrote:

It's an intriguing idea, but if it were me I'd use the simpler NPAR1WAY procedure. To me, the simpler procedure has the advantage of more explicit assumtions and (often) more power than the general test. (And it's easier for me to understand what is being tested.) By way of an analogy, if I'm testing for the difference of means, I wouldn't use PROC GLM and the ESTIMATE statement when I could use PROC TTEST.

I'm not sure that the stated criterion of "(often) more power" is a useful one. Especially when "(often)" is demonstrated by a single example. Do you have references regarding power?

What "explicit assumtions (sic)" are present in NPAR1WAY that are not present for QUANTREG's test?

--
Paige Miller
Rick_SAS
SAS Super FREQ

Yes, this is a single example. You are welcome to run a simulation study to see how well it holds in general.

I do not know what assumptions are behind the QUANTREG test, which is why I would not use it myself.

The assumptions and power behind the "median test" and the Wilcoxon test are discussed in "Should the Median Test be retired from general use?", (Freidlan and Gastwirth, 2000, TAS). That article provides evidence and gives references that show that the median test has less power in small samples, for unbalanced designs, and for asymmetric distributions than many other tests, including the Wilcoxon test. The same article also provides power analysis for various distributional assumptions.

peterinboston
Calcite | Level 5

I am new to Proc QuantReg. Comparing medians is appealing since it would be more robust to outliers than comparing means.

The appeal of Quantreg, for me,  is that it can compare medians while including other factors in the model. So you get what I'd call 'an adjusted test of medians' with QuantReg, instead of the usual unadjusted comparison of medians with Proc npar1way Wilcoxon.

The first step is to get QuantReg to duplicate the Wilcoxon result. Then I’d use Proc Quantreg to improve on a Wilcoxon test by adjusting for other factors. I’ve come as close as I can using the

   test x / rankscore (wilcoxon);

syntax below.

Note that the Wald test p=.0899 given in the first Proc QuantReg below must not be right, since the 95%CI  (-1.0039,-0.0535) for the X parameter estimate does not include 0.

I don’t understand why we don’t see a SE and a p-value in the Parameter Estimates table output of Proc Quantreg.

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',.5,1);  *<<<note .5 difference in means;

      if i>=51 then x=1;

      output;

   end;

run;

proc npar1way data=one WILCOXON;

class x;

var y ;

run;

   Wilcoxon Two-Sample Test

Statistic             2180.0000

Normal Approximation

Z                       -2.3749

One-Sided Pr <  Z        0.0088

Two-Sided Pr > |Z|       0.0176

proc quantreg data=one;

   class x;

   model y=x;

   test x;

run;

            Parameter Estimates

                           95% Confidence

Parameter   DF Estimate        Limits

Intercept    1 0.4081   -0.0237    0.8264

x         0 1  -0.4365   -1.0039 -0.0535

x 1 0   0.0000    0.0000 0.0000

                  Test Results

                       Test       Chi-

Test              Statistic DF  Square Pr > ChiSq

Wald                 2.8766  1 2.88     0.0899 

The following syntax comes closer to the Wilcoxon p-value (Wilcoxon p=.0176; quantreq p=.0168), but why are they different??

proc quantreg data=one alpha=0.05  ;

   class x;

   model y=x;

   test x / rankscore (wilcoxon);

run;

            Parameter Estimates

                           95% Confidence

Parameter   DF Estimate        Limits

Intercept    1 0.4081   -0.0237    0.8264

x         0 1  -0.4365   -1.0039 -0.0535

x         1 0   0.0000    0.0000 0.0000

                  Test Results

                       Test       Chi-

Test              Statistic DF  Square Pr > ChiSq

Rank_Wilcoxon        5.7132 1    5.71     0.0168

peterinboston
Calcite | Level 5

I asked SAS about why the results of Npar1way and Quantreg were not more similar. Below I give their response and an example they provided where the two procedures give very similar results. Apparently expecting the results to match identically was naive, since the procedures are quite different. What follows is their response.....

Summary
=========
(1) The traditional nonparametric two-sample tests are given by PROC NPAR1WAY
but this procedure is not designed to fit a model and is essentially doing
something different than PROC QUANTREG which is optimizing an objective function,
i.e. - determining the coefficient/parameter estimates that optimize the objective function.
(2) When there are ties in the response data there are different ways to compute
the rank scores in NPAR1WAY but QAUNTREG does not do any adjustment for ties.
The QUANREG developer said this is the main difference between NPAR1WAY and QUANTREG.
(3) If you have other covariates you wish to include in the analysis then you are
better served by using PROC QUANTREG which can incorporate other factors into the model.

Test program
=============
You will notice in the test program and data set simulated by the QUANTREG developer
that the NPAR1WAY results agree rather closely with QUANTREG:
(1) Regarding the "Wilcoxon Two-Sample Test" (WilcoxonTest ODS table) from NPAR1WAY
versus the Rank_Wilcoxon Test (Test 1 ODS Table) from QUANTREG:
(a) If you square the "Normal Approximation" Z value you will get something
very close to the Rank_Wilcoxon Test "Chi-Square" value from QUANTREG.
(b) The two-sided Z pvalue (Two Sided Pr > |Z|) from NPAR1WAY is very similar
the to Chi-square p-value (Pr > ChiSq) from QUANTREG.
(2) Regarding the "Median Two-Sample Test" (MedanTest ODS table) from NPAR1WAY
versus the Rank_Sign Test (Test 2 ODS table) from QUANTREG:
(a) If you square the Z value you will get something very close to the
Rank_Sign "Chi-Square" value from QUANTREG.
(b) The two-sided Z pvalue (Two Sided Pr > |Z|) from NPAR1WAY is very
similar the to Chi-square p-value (Pr > ChiSq) from QUANTREG.

%let n=100;
   
data Trial(drop=i);
     do i=1 to &n;
        if (i <= &n/2) then do;
           y = rannorm(1);
           treatment = 1;
        end;
        else do;
           y = 0.75 + rannorm(1);
           treatment = 0;
        end;
        output;
     end;
     run;


  
ods trace on / listing;
ods select WilcoxonTest MedianTest; * MedianAnalysis;
proc npar1way data=Trial Wilcoxon Median;
     class Treatment;
     var y;
     title1 "NPAR1WAY - two sample tets";
     run;

ods select ModelInfo ObjFunction ParameterEstimates Tests;
proc quantreg data=Trial alpha=0.05;
     class treatment;
     model y =  treatment / quantile=.5;
     test treatment / rankscore(Wilcoxon);
     test treatment / rankscore (median);
     title1 "QUANTREG - rankscore tests of two treatments"; 
     run;
ods trace off;

BRavo
Calcite | Level 5

According to my knowledge. T-test and Mann-Whitney (Wilcoxon) test the differences between MEANS (not medians)

IF data are normally distributed then it means mean almost same as median. So t-test would give us a p-value for difference between means (which equal medians)

If data are not normally distributed then I would use Mann-Whitney and report differences between means (with p-value). You can report medians too but there is NO real test to test that difference between medians.

That what I know. Any one who tells you use Mann Whitney or Wilcoxon, is not totally accurate because that test is based on assumptions and p-values generated from that test would be more interpreted towards the mean difference (not medians).

But I have seen people use that test to for difference between medians in some articles.

Again, you would report medians and means and p-value for the means!

SteveDenham
Jade | Level 19

I am going to differ in opinion here.  Since the nonparametric versions are rank transfomations of the data, they are in fact testing for differences in the mean ranks, which would be equivalent to differences in the medians on the untransformed scale.

Steve Denham

BRavo
Calcite | Level 5

Yes. Thanks a lot. But one thing to note. Mean and medians are not usually equal in non-parametric data. So I am not sure if you we can 100% consider that difference between means as medians.

PGStats
Opal | Level 21

Back to basics. Once your data is transformed into ranks, the mean IS equal to the median. Before the transformation however, the mean equals the median (statistically) only for symmetric distributions (i.e. normal, logistic, uniform, triangular, etc.)

The choice between different tests of location mostly depends on the weight you want to give to extreme observations. As a rule, parametric tests give them more weight than non-parametric tests (based on ranks).

PG

PG
BRavo
Calcite | Level 5

Sounds right to me. So now, we can use Wilcoxon for comparing median ranks? and report p-values for publications\

Thanks

SteveDenham
Jade | Level 19

Yes.  The clinical medicine literature is full of examples.

Steve Denham

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 24053 views
  • 14 likes
  • 8 in conversation