BookmarkSubscribeRSS Feed
_Hopper
Quartz | Level 8

I am using the following code to compute exact CI and produce the change in median (shift). This code appears to operate correctly for all visits except the last one where it switches the sign on the shift.

Last Visit

Hodges-Lehmann Estimation
Location Shift (3 - 2) -2.0000 (want 2-3 for this one also and all other stats)
95% Confidence Limits Interval Midpoint Asymptotic
Standard Error
-3.0000 -1.0000 -2.0000 0.5102

All other visits

Hodges-Lehmann Estimation
Location Shift (2 - 3) 0.0000 (this is the correct order)
95% Confidence Limits Interval Midpoint Asymptotic
Standard Error
-1.0000 0.0000 -0.5000 0.2551
 
 
How do I force SAS to always take the differences as 2-3 so it does not switch to 3-2?
proc npar1way data = maze3 wilcoxon  HL  ALPHA = 0.05;
by avisitn avisit;
class treatnp;
where treatnp in (2 3) and acat = 'Study Eye';
var chg;
EXACT WILCOXON;
ods output wilcoxontest =WT23  HodgesLehmann = HL23;
run;
5 REPLIES 5
Ksharp
Super User

I think that is due to treatnp=3 appeared before treatnp=2 in the last visit.

Here is an example:

data maze3 ;
input avisitn avisit $ treatnp chg;
cards;
1 visit1 2 23
1 visit1 2 23
1 visit1 2 23
1 visit1 3 123
1 visit1 3 123
1 visit1 3 123
2 visit2 3 23
2 visit2 3 23
2 visit2 3 23
2 visit2 2 123
2 visit2 2 123
2 visit2 2 123
;

proc npar1way data = maze3 wilcoxon  HL  ALPHA = 0.05;
by avisitn avisit;
class treatnp;
var chg;
EXACT WILCOXON;
ods output wilcoxontest =WT23  HodgesLehmann = HL23;
run;

Ksharp_0-1770795615047.png

Ksharp_2-1770795669313.png

 

If you changed the order of 2 and 3 in the last visit, you got this:

data maze3 ;
input avisitn avisit $ treatnp chg;
cards;
1 visit1 2 23
1 visit1 2 23
1 visit1 2 23
1 visit1 3 123
1 visit1 3 123
1 visit1 3 123
2 visit2 2 23
2 visit2 2 23
2 visit2 2 23
2 visit2 3 123
2 visit2 3 123
2 visit2 3 123
;

Ksharp_3-1770795750538.png

 

Ksharp_4-1770795771995.png

 

 

_Hopper
Quartz | Level 8

It is caused by the counts in the different treatments. The difference and CIs are computed on Yi - Xi where Yi in this case is the treatment with fewer records. I had to put some extra logic in the code to reverse the signs so the median difference and CIs would be in the correct direction. There isn't a way to make SAS do it the same way every time as the NPAR1WAY procedure does this on its own. 

 

For example, if we want TMT1 - TMT2 and n(TMT1)>=n(TMT2) SAS will always run the computation as TMT2-TMT1. From here the signs have to be reversed for both the CIs and the shift value (consequently LCL becomes UCL and UCL becomes LCL). This is what I learned from the statisticians at SAS.

Tom
Super User Tom
Super User

The documentation seems to say that you can pick which value of the class variable is the reference value.

You can specify the reference class by using the HL(REFCLASS=) option. REFCLASS=1 specifies the first class that is listed in the "Wilcoxon Scores" table, and REFCLASS=2 specifies the second class. REFCLASS='class-value' identifies the reference class by the formatted value of the CLASS variable.

 

But trying it using @Ksharp 's example program it does not seem to actually make any difference.

_Hopper
Quartz | Level 8

Using the option (refclass =1) didn't make any difference. The same ones are 3-1 instead of 1-3. 

_Hopper
Quartz | Level 8

Update refclass does make a difference if the data are sorted first like this:

 

proc sort data = xxx;

by avisitn avisit descending treatment;

run;

 

*this puts the control group first by visit then

 

proc npar1way data = xxx wilcoxon HL(refclass = 1) alpha = 0.05 <<<<-now it computes the difference I want every time regardless of record counts.

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.

Explore 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
  • 5 replies
  • 482 views
  • 5 likes
  • 3 in conversation