BookmarkSubscribeRSS Feed
AlexeyS
Pyrite | Level 9

i want to know how can i get the value of wilcoxon signed rank test(one sample).

for example, P(V>=85)=P(V<=84)=0.0844.

how can i get 0.0844?

i didn't find any function where i can calculate a wilcoxon value. i know there are wilcoxon table and i can go to see the value there but ii need to get the value automatically. Thank you

8 REPLIES 8
FreelanceReinh
Jade | Level 19

The Wilcoxon signed rank test can be computed with PROC UNIVARIATE. The default output includes the value of the test statistic S and the corresponding p-value "Pr >= |S|": see section "Tests for Location" of the output, where "Test" is "Signed Rank".

 

I'm not quite sure which statistic is denoted by V in your example, which obviously contains a typo (do you mean "<" rather than ">="?). Moreover, you don't tell which sample size n your probability 0.0844 is calculated for.

 

The formulae which SAS uses are documented, e.g. for version 9.2, in the relevant section of the Procedures Guide. Please note in particular that SAS switches to an approximate test for n>20, more precisely: for n_t>20. Also, ties are handled in a specific way in this case.

 

The MU0= option of the PROC UNIVARIATE statement will be useful for you if you want to perform the test for a MU0 value not equal to the default value zero.

 

You can use an ODS OUTPUT statement to extract the p-value from the output (for further processing, if needed) as shown in the following example:

data sample;
do i=1 to 10;
  x=int(30*ranuni(271828));
  output;
end;
run;

ods output TestsForLocation=tfl;
proc univariate data=sample mu0=15;
var x;
run;

proc print data=tfl;
where test='Signed Rank';
var pvalue;
run; /* 0.7109 */

 

 

 

AlexeyS
Pyrite | Level 9

Thank you for your answer.

i run my code with proc univariate and got right signed test results, but about wilcoxon test i got something strange, i got results, that if i divide this result by 2, i got result from book.

my data (i respresent d=y-x): n=15

0.47

0.88

1.41

1.06

-0.12

-0.24

-0.59

0.58

0.18

-0.41

1.00

-0.35

0.76

0.71

-1.18

 

Can you explain what is right? Thank you

 

P(=P(V>=85)=1-P(V<=84)=0.0844

i got the next table : 

Tests for Location: Mu0=0
Test
Statistic
p Value
Student's tt
1.466836
Pr > |t|
0.1645
SignM
1.5
Pr >= |M|
0.6072
Signed RankS
25
Pr >= |S|
0.1688
 
FreelanceReinh
Jade | Level 19

Apparently, the author of your book performed a one-sided Wilcoxon signed rank test (hopefully with good reason), whereas the p-value from PROC UNIVARIATE corresponds to a two-sided test. Indeed, you have to divide the resulting p-value by two in order to obtain the appropriate p-value for the one-sided test.

 

Please note that this rule does not hold in general. It is applicable here, because we have

 

  1. symmetry of the distribution of the test statistic S
  2. The calculated value of the test statistic for your data, 25, deviates from zero in the direction of the alternative hypothesis (that the median of the distribution of differences D=Y-X is positive).

(Cf. this older thread.)

AlexeyS
Pyrite | Level 9

Thank you for your answer.

As i understood i got p_value that corresponds to a two-sided test, and then if i check positive hypothesis, i have to divide the p-value by 2. right?

but if i want to check alternative hypothesis, negative, how can i find the p-value? can you explain me please?

thank you

FreelanceReinh
Jade | Level 19

The null and alternative hypotheses and the significance level a have to be specified before even looking at the data and must not be changed afterwards, as this would invalidate the conclusions.

 

Let D denote the (true, unknown) median of the distribution of differences D=Y-X you consider. There are three possible pairs of hypotheses, depending on your research question: one-sided hypotheses in one direction (cases 1 and 2) or symmetric, two-sided hypotheses (case 3).

 

Case 1: H0: D<=0 vs. A: D>0

 

a) Let s denote the calculated value of test statistic S. With your data you obtained s=25. In general: If s>=0 (i.e. it deviates from 0 in the direction of the alternative hypothesis A, if at all), the appropriate one-sided p-value is half the (two-sided) p-value p ("Pr >= |S|") reported by PROC UNIVARIATE: p/2. In your example: 0.0844.

 

b) If s<0, say, s=-25, the one-sided p-value would have been 1-(p/2). Since this value would be >0.5, it would be obvious that it is >a whatever reasonable significance level a (such as 0.05) you had chosen. So, H0 could not be rejected.


Case 2: H0: D>=0 vs. A: D<0

 

a) If s<=0 (i.e. it deviates from 0 in the direction of A, if at all), the appropriate one-sided p-value is again p/2.

 

b) If s>0 (like with your data), the one-sided p-value is 1-(p/2). Again this would be >0.5 in general; for your data in particular it is 0.9156>0.5, hence far too large to reject the null hypothesis at any reasonable significance level a.


Case 3: H0: D=0 vs. A: D ne 0

 

In this case you can use the test results from PROC UNIVARIATE directly.

AlexeyS
Pyrite | Level 9

Thank you very much. 

I have another one question.

I want to weight every difference(time weight) and then use  wilcoxon signed rank test.

How can i weight wilcoxon signed rank test? as i understood from forum it doesn't  work in proc univariate? Maybe you know what i should do?

In your opinion can i weight observation in sign test too? as i understand i don't think the weight will be influence, but maybe i don't undesrand something?

Thank you

FreelanceReinh
Jade | Level 19

I regret am not familiar with (time-)weighted versions of these two nonparametric tests and, indeed, PROC UNIVARIATE does not compute such tests.

 

So, if you don't have access to software where these tests are implemented, but you know a research paper where the relevant formulas and algorithms are presented, you could try and program these in SAS. This would probably be an interesting contribution to a SAS conference.

AlexeyS
Pyrite | Level 9

thank you a lot.

see this link : https://communities.sas.com/t5/SAS-Statistical-Procedures/Weighted-Ranked-Sign-Test-Proc-Univariate/...

 

Posts: 152
 
Re: Weighted Ranked Sign Test & Proc Univariate[ New ]

If you create the signed ranks by yourself, and if you then run these signed ranks through PROC SURVEYMEANS, then you can obtain a weighted signed rank test and its significance probability (using the t-test comparison to a mean of zero).  The significance probability of the t-test for such created signed ranks equals the significance probability of the signed rank test for these signed ranks as well as the significance test for the signed rank test on the original values.

 

To create signed ranks from the original values,

  1. use the ABS(x) function in a DATA step to create the absolute values of the original values;

  2. use the SIGN(x) function in a DATA step to extract the signs of the original values;

  3. use PROC RANK to rank the absolute values of the original values; and

  4. use a DATA step to create signed ranks by multiplying the signs of the original values times the ranks of the absolute values

        of  the original values.

 

Then use these signed ranks and the weights for each value in PROC SURVEYMEANS.

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 7667 views
  • 0 likes
  • 2 in conversation