<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Deriving SAS' Wilcoxon Signed Pair procedure in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/Deriving-SAS-Wilcoxon-Signed-Pair-procedure/m-p/740340#M35982</link>
    <description>Here's a fully worked example, you can test your methods against this. You'll have to find the example program (name is at bottom of page) in your installation. I'm not sure where they're being saved online anymore. &lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/procstat/procstat_univariate_examples13.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/procstat/procstat_univariate_examples13.htm&lt;/A&gt;</description>
    <pubDate>Tue, 11 May 2021 01:57:40 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2021-05-11T01:57:40Z</dc:date>
    <item>
      <title>Deriving SAS' Wilcoxon Signed Pair procedure</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Deriving-SAS-Wilcoxon-Signed-Pair-procedure/m-p/740330#M35980</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I trying to write an algorithm that matches exactly how SAS performs its Wilcoxon Signed Rank test (ultimately, I would like to do this in R).&lt;/P&gt;&lt;P&gt;I tried to follow SAS’ documentation of the Wilcoxon Signed Rank test, which you can see &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/procstat/procstat_univariate_details17.htm" target="_blank"&gt;here&lt;/A&gt;, but my result ended up quite differently than SAS’ result. Specifically, I got a value for my test statistic, S, = -6, while SAS reports that S = 7.5.&lt;/P&gt;&lt;P&gt;Here is my code. I tried to put a few comments in SAS explaining how my work aligned with SAS’ documentation.&amp;nbsp;&lt;/P&gt;&lt;P&gt;If anyone can help me to understand why my algorithm and/or test statistic doesn't match SAS' algorithm / test statistic, I would be very grateful.&lt;/P&gt;&lt;PRE&gt;/*made up data (actually, the data is scorelines from Celtic Football Club in Scotland, but that doesn't matter)*/
data test;
input v1
	  v2;
datalines;
5 1
1 1
6 0
1 0
1 2
3 0 
5 0 
2 1
3 2
1 0
3 0
1 0 
;

/*Run SAS' Wilcoxon signed rank test*/
proc univariate data = test;
	var v1 v2;
run; 
/*note that here S = 7.5*/

/*derive x_[i}*/
data test2;
	set test;
	diffVar = v1 - v2;
	diffVarAbs = abs(diffVar);  
run; 

/*constant is \mu_{0}*/
proc sql noprint;
	select mean(diffVar) into: constant TRIMMED
	from test2;
quit; 

/*note that no observations have a difference equal to \mu_{0} so I don't have to discard any observations*/

/*derive |x_{i} - \mu| */
data test3; 
	set test2;
	scaledDiffVar = abs(diffVar - &amp;amp;constant);
run; 

/*derive r_{i}*/
proc rank data = test3 out = test4;
	var scaledDiffVar;
	ranks Finish;
run; 

/* filtering observations such that x_{i} &amp;gt; \mu_{0}*/
data test5;
	set test4; 
	WHERE diffVar &amp;gt; &amp;amp;constant;
run; 

/*constant2 is n(t)*/
proc sql noprint;
	select count(v1) into: constant2 TRIMMED
	from test3;
quit; 

/*constant3 is the sum of r_{i}s*/
proc sql noprint;
	select sum(Finish) into: constant3 TRIMMED
	from test5;
quit; 


/*Note that I only run the below step because I couldn't figure out how else to get a dataset with one observation*/
data test6;
	set test5;
	WHERE v2 = 1;
run; 

/*calculate S*/
proc sql; 
	select &amp;amp;constant3 - (&amp;amp;constant2 * (&amp;amp;constant2 + 1)) / 4 into: constant4 TRIMMED
	FROM test6  ;
quit; 
/*note that now S = -6*/&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 May 2021 23:53:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Deriving-SAS-Wilcoxon-Signed-Pair-procedure/m-p/740330#M35980</guid>
      <dc:creator>pywils</dc:creator>
      <dc:date>2021-05-10T23:53:49Z</dc:date>
    </item>
    <item>
      <title>Re: Deriving SAS' Wilcoxon Signed Pair procedure</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Deriving-SAS-Wilcoxon-Signed-Pair-procedure/m-p/740339#M35981</link>
      <description>Are you certain PROC UNIVARIATE is what you should be using here? I would have assumed PROC NPAR1WAY would be more appropriate here.&lt;BR /&gt;</description>
      <pubDate>Tue, 11 May 2021 01:55:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Deriving-SAS-Wilcoxon-Signed-Pair-procedure/m-p/740339#M35981</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-05-11T01:55:10Z</dc:date>
    </item>
    <item>
      <title>Re: Deriving SAS' Wilcoxon Signed Pair procedure</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Deriving-SAS-Wilcoxon-Signed-Pair-procedure/m-p/740340#M35982</link>
      <description>Here's a fully worked example, you can test your methods against this. You'll have to find the example program (name is at bottom of page) in your installation. I'm not sure where they're being saved online anymore. &lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/procstat/procstat_univariate_examples13.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/procstat/procstat_univariate_examples13.htm&lt;/A&gt;</description>
      <pubDate>Tue, 11 May 2021 01:57:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Deriving-SAS-Wilcoxon-Signed-Pair-procedure/m-p/740340#M35982</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-05-11T01:57:40Z</dc:date>
    </item>
    <item>
      <title>Re: Deriving SAS' Wilcoxon Signed Pair procedure</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Deriving-SAS-Wilcoxon-Signed-Pair-procedure/m-p/740627#M36000</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/380685"&gt;@pywils&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/380685"&gt;@pywils&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE&gt;/*Run SAS' Wilcoxon signed rank test*/
proc univariate data = test;
	var v1 v2;
run; 
/*note that here S = 7.5*/&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Note that you perform&amp;nbsp;&lt;EM&gt;two&lt;/EM&gt; Wilcoxon signed rank tests: one for &lt;FONT face="courier new,courier"&gt;v1&lt;/FONT&gt; and one for &lt;FONT face="courier new,courier"&gt;v2&lt;/FONT&gt;. That &lt;FONT face="courier new,courier"&gt;S=7.5&lt;/FONT&gt; is the test statistic for &lt;FONT face="courier new,courier"&gt;v2&lt;/FONT&gt;. What you want, however, is the&amp;nbsp;Wilcoxon signed rank test for the &lt;EM&gt;difference&lt;/EM&gt;&amp;nbsp;&lt;FONT face="courier new,courier"&gt;v1-v2&lt;/FONT&gt;&amp;nbsp;-- and that with a non-default µ0 (according to your code), i.e.:&lt;/P&gt;
&lt;PRE&gt;&lt;FONT size="4"&gt;proc univariate data=&lt;STRONG&gt;&lt;FONT color="#3366FF"&gt;test2 mu0=&amp;amp;constant&lt;/FONT&gt;&lt;/STRONG&gt;;
var &lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;diffVar&lt;/STRONG&gt;&lt;/FONT&gt;;
run;&lt;/FONT&gt; &lt;/PRE&gt;
&lt;P&gt;Now your &lt;FONT face="courier new,courier"&gt;S=-6&lt;/FONT&gt; is confirmed.&lt;/P&gt;</description>
      <pubDate>Tue, 11 May 2021 22:17:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Deriving-SAS-Wilcoxon-Signed-Pair-procedure/m-p/740627#M36000</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-05-11T22:17:07Z</dc:date>
    </item>
  </channel>
</rss>

