# Wilcoxon Signed Rank when positive and negative differences are equal in magnitudes

I've run into some trouble. To begin with, I have no formal education in statistics, so much of what I do is self learned and I may be blissfully unaware of some fundamentals that I've completely missed.

I'm working with some data where we have taken repeated samples from patients with a 10 minute interval, thus the samples are paired. When looking at the data, Sample 1 and Sample 2 have the same mean and median, but there are differences on a sample to sample basis, i.e. Sample1-Sample2 is not 0. Despite this, when I run a Wilcoxon Signed Rank test on several of our variables (which all behave the same), the Signed rank is not significant. My initial thought was that the Signed rank would be sensitive to any pair-wise differences, and that any pair-wise difference would add up to eventually reach significance, regardless of the direction of the differences.

Now that I've read up on the Signed rank, it appears to me that it wont be sensitive to data where the differences are both negative and positive in equal magnitudes? Am I wrong in this? If the W+ =/ W-, and both are large, the WSR will not find it significant? When I make a simple vector of Sample1-Sample2, it's definitely not 0, shouldn't the Signed rank detect this?

I've added my data for one of the variables below if it helps.

EDIT: So, I realized that my question was flawed in many ways. First I gave you one of the only variables that actually gave the expected results. I've remedied this. But I realize that I omitted one fundamental part of why I'm confused.

So, we have paired samples from the various patients. Each sampling session was assigned to intervention (between samples) or control (no intervention between samples). I've included data for both groups below. Now, a WSR tells me that there is no difference between Sample 1 and Sample 2 in neither group, however, when I run a Sum Rank on the absolute differences between the groups, the difference is significantly different. I cannot possibly phantom how this can be the case. I.e. how can the pair-wise difference be greater in the intervention group compared to the control group (sum rank), if there is no difference there to begin with (Signed rank)?

Sample1I <- c(4.2,3.9,3.5,3.2,4.2,4.8,5.2,5.6,4.8,4.6,3.8,3.9,3.4,3.5,3.5,2.8,1.9,2.1,2.5,2.3,1.8,3.4,2.8,2.8,2.4,2.5,3.4,3.2,4.3,3,3.1,4.1,3.5,2.2,2.3,2.5,2.9,3.3,3,3.6,3.3,4,3.6,3.4,3.9,4.1,2.7,3.1,3,3.6,2.5,2.6,2.8,6.1,5.7,4.5,5.7,5.6,3.6,3.6,2.9,2.1,3,2.7,2.6,2.6,3,3,4.9,3,3.3,4.8,4.4,5.5,3.4,3.9,2,2.4,3.5,2,2.8,2.3,2.8,3.1,3.6,1.7,4,5,2.2,2.4,2.4,4,3.2,3.9,4,4.6,6,1.5,1.9,5.1,3.9,3.2,4.6,3.1,3,3.3,3.1,3.2,3.4,3.6,2.5,2.2,2.2,2.5,2.5,3,5.1,3.2,4.2)

Sample2I <- c(4.8,3.7,3.4,3.3,4.2,5.6,4.8,5.7,4.8,4.8,3.9,3.7,3.3,3.4,3.5,2.9,2.1,2.3,2.2,2.2,1.8,3,2.4,2.7,3,2.6,3.4,3.3,4.5,3.3,3.5,4.4,3.6,2.1,2.3,2.5,2.9,3.2,2.9,3.6,3.2,4.1,3.4,3.1,4,4,2.6,3.3,2.8,3.7,2.6,2.7,2.9,5.9,5.5,4.7,5.2,5.8,4.1,3.7,3.4,2.1,3.3,2.7,2.6,2.6,2.9,3.2,4.9,3.2,3.3,5.2,4.2,5,3.5,3.9,2.5,2.6,2.7,2.1,2.2,2.1,2,3.2,3.7,1.6,3.9,4.6,2.3,2.5,2.5,3.7,2.8,3.9,3.9,3.5,6.2,1.5,1.9,5.2,3.8,3.2,4.6,3,3.5,3.3,3,3.2,3.5,3.8,2.6,2.2,2.2,2.5,2.8,3.3,4.9,3.3,4.1)

wilcox.test(Sample1I,Sample2I,paired=T)

Wilcoxon signed rank test with continuity correction

data:  FLIP1y$$Lactate1 and FLIP1y$$Lactate2
V = 1998, p-value = 0.4716
alternative hypothesis: true location shift is not equal to 0

##

Sample1Cont <- c(3.2,4.2,6.3,6.6,5.2,5.4,4.4,3.6,2.5,2.6,2.5,3.8,
1.8,3.2,1.8,1.3,2.2,2.8,2.6,2.7,3.1,4.1,3.8,4.5,2.7,1.7,1.8,3.3,3,2.3,7.1,6.3,2.1,4,3.1,3.4,4.3,2.4,2.2,1.8,2.4,3.3,3.5)

Sample2Cont <- c(3.1,4,6.3,6.4,5.2,5.3,4.5,4,2.5,2.8,2.5,3.9,1.7,3.2,1.8,1.3,2.6,2.7,2.5,2.7,3.1,3.9,3.5,4.5,2.8,1.7,1.8,3.3,3,2.3,7.1,6.3,2.1,4.4,3.2,3.5,4.5,2.4,2.1,1.8,2.4,3.3,3.8)

wilcox.test(Sample1Cont,Sample2Cont,paired=T)

Wilcoxon signed rank test with continuity correction

data:  Sample1Cont and Sample2Cont
V = 99.5, p-value = 0.5883
alternative hypothesis: true location shift is not equal to 0

Warning messages:
1: In wilcox.test.default(Sample1Cont, Sample2Cont, paired = T) :
cannot compute exact p-value with ties

###

wilcox.test(abs(Sample1I-Sample2I),abs(Sample1Cont-Sample2Cont),paired=F)

Wilcoxon rank sum test with continuity correction

data:  abs(Sample1I-Sample2I) and abs(Sample1Cont-Sample2Cont)
W = 3421.5, p-value = 0.0008429
alternative hypothesis: true location shift is not equal to 0



• Try to make sure your code will actually run: you've got spaces in the variable names. Jan 8, 2021 at 7:14

Ok, so consider the first sets of data

> d<-Sample1I-Sample2I
> d2<-outer(d,d,"+")/2
> diag(d2)<-NA
> summary(as.vector(d2),na.rm=TRUE)
Min.  1st Qu.   Median     Mean  3rd Qu.     Max.     NA's
-0.70000 -0.10000  0.00000 -0.00252  0.10000  0.95000      119


The location summary that the signed rank test uses is the median pairwise mean, and this is exactly zero

So, yes, the signed rank test should say there isn't a difference.

The rank-sum test at the end of the revised question asks if the absolute value of the difference is the same for the two data sets. It isn't. That's not surprising.

Suppose, as an unrealistic extreme case, that the two sets of data were the same, except that the first set was measured in inches and the second set in centimetres. (Because America). The second set of numbers would then be bigger by a factor of 2.54, so the rank-sum test would find a difference, even though neither signed-rank test found a difference.

The two signed rank tests are asking whether the paired differences tend to be centered around zero. The rank sum test is asking whether the two sets of paired differences are on the same scale and of the same size (in some imprecise sense). These are very different questions.

Moving away from rank tests, because they're harder to think about, suppose you did a paired t-test on whether your left thumb was longer than your right thumb, and a paired t-test on whether your left big toe was longer than your right big toe. I would expect unimpressive p-values; fingers and toes are reasonably left-right symmetric. But if you then asked whether the absolute difference in thumb lengths was the same as the absolute difference in toe lengths, I wouldn't be at all surprised to find a difference: there isn't any finger vs toe symmetry.

• Thanks for your reply Thomas. So in a case where I don't care about the direction of a pair-wise change, i.e. I don't care that the median difference is 0, I care that there actually ARE differences between sample 1 or 2 (the assumption when taking these samples are that they are not variable, which is why any difference is of interest regardless of direction) the Wilcoxon test is not the right test for me? Jan 8, 2021 at 8:22
• Yes. I'd just quibble that it's not the median. For the signed-rank test it's the difference in median pairwise means, and there isn't any univariate summary statistic that agrees with the rank sum test Jan 8, 2021 at 8:39

You didn't do a Wilcoxon Signed Rank test, you did a Wilcoxon Rank Sum test

The Wilcoxon signed rank test does show evidence of a difference in locations

> wilcox.test(Sample1,Sample2,paired=TRUE)

Wilcoxon signed rank test with continuity correction

data:  Sample1 and Sample2
V = 2261, p-value = 0.02602
alternative hypothesis: true location shift is not equal to 0

• Hi Thomas, Thanks for alerting me to my mistakes in the question. I was uncareful and posted one of the variables that actually fell out statistically as expected, I've remedied my mistake and added fundamental parts to the question that have me confused, which I stupidly omitted in my original version. Jan 8, 2021 at 7:52