Programming the statistical procedures from SAS

median and mean tests for several classes

Accepted Solution Solved
Reply
Super Contributor
Posts: 412
Accepted Solution

median and mean tests for several classes

Hi,

 

ususally when doing a median test I use the proc npar1way - I have a certain data variable with divised into 2 classes and i d the test to compare the medians for each class.

 

But when I have more than 2 classes, say 3, then I have to make proc npar1way 3 times because I have 3 pairs. Is it possible for SAS to do all the different pairwise median tests within the same procedure (like this don't have to repeat the same procedure 3 times)?

 

Same question applies for the mean test proc ttest.

 

Thank you! 


Accepted Solutions
Solution
‎10-27-2016 11:42 PM
Super Contributor
Posts: 412

Re: median and mean tests for several classes

Thanks Reeza for the guidance. I will summarize here the discussion and put it as the solution like this its clear to future readers:

 

1) Median test: it is done with proc npar1way for 2 samples. Can do pairwise median comparison for more than 2 samples if add the DSCF option. But note that the DSCF method deosn't include a continuity correction in the Wilcoxon test statistic, while "normal"  proc npar1way for 2 samples by dfault does (although you can include the "correction=no" option so it doesn't.

 

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

 

2) Mean test: for 2 samples it is done with proc ttest. Can do pairwise mean comparison for more than 2 samples with proc GLM and ANOVA, but should read the docs for the details:

 

http://support.sas.com/kb/45/428.html

 

https://support.sas.com/documentation/cdl/en/statug/63347/HTML/default/viewer.htm#statug_anova_sect0...

 

  

View solution in original post


All Replies
Grand Advisor
Posts: 16,906

Re: median and mean tests for several classes

This is called pairwise comparison.

 

You can do it in certain procs and not others. PROC GLM/ANOVA will allow pairwise comparison, unfortunately NPAR1WAY doesn't have pairwise AFAIK. 

Grand Advisor
Posts: 16,906

Re: median and mean tests for several classes

And google proves me wrong...

look at the DSCF on the PROC NPAR1WAY statement. 

 

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

 

Super Contributor
Posts: 412

Re: median and mean tests for several classes

Hi Reeza,

 

I tried the DSCF and it worked, but the results that I get with DSCF are somewhat different than when I am doing an individual pair median comparison. Is it normal?

 

Here is the code 

 

data test3;
set test;
if group =1 or group =3;
run;

/*for the individual pair wilcoxon test*/
ods graphics off;
ods output wilcoxontest=a_3;
proc npar1way data=test3 wilcoxon median ;
var data;
class group;
run;


/*using DSCF*/
proc npar1way data=test dscf ;
var data;
class group;
run;
Grand Advisor
Posts: 16,906

Re: median and mean tests for several classes

define different. I can't see your data or output. 

 

 

Super Contributor
Posts: 412

Re: median and mean tests for several classes

here is my original data "test":

 

data test;
input data group;
datalines;
1	1
2	1
3	1
4	1
5	1
6	1
7	1
8	1
9	1
10	1
11	1
12	1
13	2
14	2
15	2
16	2
17	2
18	2
19	2
20	2
21	2
22	2
23	2
24	3
25	3
26	3
27	3
28	3
29	3
30	3
31	3
;
run;

when I do the dscf option:

/*using DSCF*/
ods graphics off;
ods output dscf=b;
proc npar1way data=test dscf ;
var data;
class group;
run;

I get a Wilcoxon Z = -3.7033 for group 1 vs group 3.

 

Whereas when I do a regular median test using group 1 and group 3:

data test1_3;
set test;
if group =1 or group =3;
run;

/*for the individual pair wilcoxon test*/
ods graphics off;
ods output wilcoxontest=a_3;
proc npar1way data=test1_3 wilcoxon median ;
var data;
class group;
run;

I get a Wilcoxon Z = 3.6647

Grand Advisor
Posts: 16,906

Re: median and mean tests for several classes

Super Contributor
Posts: 412

Re: median and mean tests for several classes

ok I think I understand, its becasue the DSCF method deosn't include a continuity correction in the Wilcoxon test statistic.

 

And in fact, when I did a regular 2 sample npar1way median test and included the "correction = no" option, I got the same Wilcoxon Z as with the DSCF method.

Is it possible to include the continuity correction when doing the DSCF method? If no, I guess this will answer the first part of my question.

 

As for the second part, is it possible to compare the means of several samples in one step? When I used proc ttest and included more than 2 classes I got an error message that there are more than 2 levels.

 

Thank you! 

Grand Advisor
Posts: 16,906

Re: median and mean tests for several classes

Ttests are between two samples. ANOVA is for more than 2 samples. 

It probably has a multiple comparison option if you check the docs. 

Solution
‎10-27-2016 11:42 PM
Super Contributor
Posts: 412

Re: median and mean tests for several classes

Thanks Reeza for the guidance. I will summarize here the discussion and put it as the solution like this its clear to future readers:

 

1) Median test: it is done with proc npar1way for 2 samples. Can do pairwise median comparison for more than 2 samples if add the DSCF option. But note that the DSCF method deosn't include a continuity correction in the Wilcoxon test statistic, while "normal"  proc npar1way for 2 samples by dfault does (although you can include the "correction=no" option so it doesn't.

 

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

 

2) Mean test: for 2 samples it is done with proc ttest. Can do pairwise mean comparison for more than 2 samples with proc GLM and ANOVA, but should read the docs for the details:

 

http://support.sas.com/kb/45/428.html

 

https://support.sas.com/documentation/cdl/en/statug/63347/HTML/default/viewer.htm#statug_anova_sect0...

 

  

☑ This topic is SOLVED.

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

Discussion stats
  • 9 replies
  • 388 views
  • 4 likes
  • 2 in conversation