1
$\begingroup$

for simplicity, let's say I have a dataframe called df, with two variables - weight_0 and weight_1. weight_0 describes the weight of participants before intervention, and weight_1 describes the weight of the same participants after intervention. Now, I want to know if the entire cohort demonstrated weight loss during the trial, so I would use the paired Wilcoxon test to compute P-value. I used to be a Python user, so I did it with the pingouin package

import pingouin as pg
pg.wilcoxon(x=df["weight_0"], y=df["weight_1"])

The output would be

|W-val|alternative|p-val|RBC|CLES|
|Wilcoxon|11459.5|two-sided|0.004|0.214|0.535|

The same would happen if I would use the famous scipy

import scipy.stats as stats
stats.wilcoxon(x=df["weight_0"], y=df["weight_1"])
WilcoxonResult(statistic=11459.5, pvalue=0.003966344096710916)

I started using R on the same dataset, and to my suprise I got a different P value

wilcox.test(x = df$weight_0, y = df$weight_1, paired = T)
Wilcoxon signed rank test with continuity correction

data: df$weight_0 and df$weight_1
V = 13112, p-value = 0.02105
alternative hypothesis: true location shift is not equal to 0

However, If I calculte a variable which is the difference in weight,

weight_del = weight_1 - weight_0

I get a result which is similar to Python:

wilcox.test(df$weight_del, mu = 0)
Wilcoxon signed rank test with continuity correction

data: df$weight_del
V = 11460, p-value = 0.003972
alternative hypothesis: true location is not equal to 0

I have seen nomerous posts online regarding different results between R and Python while performing the Wilcoxon test. However, I don't understand why I get similar results if I'm using the 'del' variable and what is happening under the hood. In addition, I don't have a small N which is described in some posts as the source of difference (N ~ 200).

$\endgroup$
2
  • 2
    $\begingroup$ Do you have individuals with zero change? The first thing wilcox.test does in the paired setting is to do the subtraction, and it then drops zeroes. Those steps could potentially be sensitive to rounding error, as the sci.py.stats.wilcoxon documentation also notes. $\endgroup$ Commented Feb 26 at 20:17
  • $\begingroup$ 1) What are you trying to prove? What is a meaningful comparison? Difference of means? Difference of medians? (but then, why medians and not means? One population stochastically superior to the other? Explain the goal, then we can discuss which test, which flavor, etc... 2) Which Wilcoxon test? Wilcoxon signed rank test I assume (1-sample Wilcoxon, which would be applicable to your paired data). Or Wilcoxon rank sum (akak Mann-Whitney)? Or? $\endgroup$
    – jginestet
    Commented Feb 27 at 2:50

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.