# Does Wilcoxon Signed Rank (paired test) in R automatically analyse data by row?

I have multiple rows of observation periods [OP] (of varying durations) showing the average food intake rate of the first quarter of the OP compared to the last quarter of the OP. See the table below.

OP Intake.Q1 Intake.Q4
1 6 6
2 19.5 5
3 5.1 2.5
4 4.7 2.1
5 10.6 5.4

I want to find out if there is a significant difference between the first and the last quarter of each OP.

If I run a Wilcoxon test in R:

wilcox.test(IntakeQ1, IntakeQ4, alternative=("two.sided"), paired=TRUE)

My question is: How will R analyse this data, because I need it to compare the time points in each OP then give me a final result of whether intake rate significantly changes during observation period.

So will it compare 6 & 6, then 19.5 & 5, then 5.1 and 2.5, etc. then give me a final output, or will it aggregate everything in Intake.Q1 and compare to everything in Intake.Q4?

Thank you.

Yes, since a X and Y are provided and paired=TRUE option is used.

From help:

"If both x and y are given and paired is TRUE, a Wilcoxon signed rank test of the null that the distribution of of x - y (in the paired two sample case) is symmetric about mu is performed."

• I'm sorry, just to clarify, it will analyse row by row? Feb 19, 2021 at 17:36
• Yes, it will pair the first x with the first y, the second x with the second y, etc... Feb 19, 2021 at 18:29
• Nice idea to quote R help. (+1) Feb 20, 2021 at 1:34

Putting your data into R as vectors q1 and q4:

q1 = c(6, 19.5, 5.1, 4.7, 10.6)
q4 = c(6,  5,   2.5, 2.1,  5.4)


Your paired Wilcoxon test gives the following results:

wilcox.test(q1, q4, pair=T)  # 2-sided is default

Wilcoxon signed rank test with
continuity correction

data:  q1 and q4
V = 10, p-value = 0.1003
alternative hypothesis:
true location shift is not equal to 0

Warning message:
In wilcox.test.default(q1, q2, pair = T) :
cannot compute exact p-value with zeroes


Now find the five paired differences.

d = q1 - q4;  d
[1]  0.0 14.5  2.6  2.6  5.2

wilcox.test(d)  # 2-sided test with 0 null is default

Wilcoxon signed rank test
with continuity correction

data:  d
V = 10, p-value = 0.1003
alternative hypothesis:
true location is not equal to 0

Warning message:
In wilcox.test.default(d) :
cannot compute exact p-value with zeroes


The result is exactly the same as for the 'paired' test. The paired test begins by finding the paired differences and then doing the one-sample Wilcoxon signed-rank test on the differences (instead of the two-sample Wilcoxon rank sum test on the two samples, as if indepencent).

• However, upon taking differences, you do have a a $$0$$ difference and a tie (at 2.6) for two out of the five differences.
(2) Neither the $$0$$ nor the tie is the reason one fails to get significant results at the 5% level--for just the five subjects you list as examples.
The following simulation repeatedly jitters the data very slightly to avoid $$0$$ and to break ties. None of the jittered data give significant results at the 5% level:
pv = replicate(10^4, wilcox.test(
d+runif(5, -.001,.001))$p.val) summary(pv) Min. 1st Qu. Median Mean 3rd Qu. Max. 0.06250 0.06250 0.06250 0.09354 0.12500 0.12500  Also, with only five subjects the smallest possible P-value for a one-sided test is $$1/32$$ and the smallest for a 2-sided test is $$1/16 = 0.0625,$$ achieved as the min in the simulation. (3) The data seem to be numerical (instead of merely ordinal). Even if we assume differences are normal (and with only $$n=5$$ of them, there's no use trying to test that), a paired t test comes nowhere near significance at the 5% level, partly because of a large variance. t.test(d)$p.val