8
$\begingroup$

I found this post saying that one should test for the median difference instead of the difference in medians, in particular if the data is skewed: http://onbiostatistics.blogspot.com/2015/12/median-of-differences-versus-difference.html The authors says "median of differences is the correct number to be used and is the number that corresponding to the signed rank test".

I did not find good explanations for this. My question: are there any reasons from a statistical perspective why the median difference should be preferred over the difference in medians?

To give some more background: The differences are paired. Moreover, the paired differences are highly skewed to the right (in my real data set), which is why I want to use a bootstrap hypothesis test.


Example

Suppose I have a two samples x1 and x2 as below. The samples are paired, for instance the id could specify the person and x1 could be a measurement before intervention and x2 after the intervention (for the same person).

id    x1      x2    difference
1   1.37    1.68    -0.31   
2   2.18    2.99    -0.80   
3   1.16    3.24    -2.07   
4   3.60    3.08    0.52    
5   2.33    2.19    0.13    

The median difference would be: median(x1 - x2) = median(difference) = -0.31

The difference in medians would be: median(x1) - median(x2) = -0.80.

$\endgroup$
10
  • $\begingroup$ Concerning the last sentence before your example. Are you saying that you have differences arising from pairs and that those differences are right skewed? How many differences? What hypothesis do you want to test? (That the population median is 0? Or something else?) Finally, can you say why you want to use a re-sampling method rather than a nonparametric test such as Wilcoxon SR? $\endgroup$
    – BruceET
    Apr 6, 2020 at 7:04
  • $\begingroup$ @BruceET. Yes, in my data set I have differences arising from pairs (as shown in the example) and these differences (corresponding to the difference column in the example) are right skewed. I have approx. 3500 such difference values. I want to test the H0: median(difference) = 0 against H1: median(difference) > 0 (or alternatively H0: median(x1) - median(x2) > 0 against H1: median(x1) - median(x2) > 0). $\endgroup$
    – jollycat
    Apr 6, 2020 at 8:32
  • $\begingroup$ @BruceET. I have considered nonparametric re-sampling methods because, based on the observed 3500 differences, it does not seem that common assumptions (such as assumption of normality or for other tests assumption of symmetry) are fulfilled. In addition, I like re-sampling methods because of their flexibility in the test statistic (differences in medians or median difference can simply be defined as test statistic without issues). Please let me know if something in my answer is unclear or if you have other questions. $\endgroup$
    – jollycat
    Apr 6, 2020 at 8:33
  • 2
    $\begingroup$ Among other points "difference in medians" ignores the pairings while "medians of differences" uses it. So if the pairings are meaningful the latter may be preferable $\endgroup$
    – Henry
    Apr 6, 2020 at 17:22
  • 1
    $\begingroup$ I suspect that even that loses much of the pairing information $\endgroup$
    – Henry
    Apr 6, 2020 at 18:31

1 Answer 1

8
$\begingroup$

Data. There are some minor discrepancies (maybe from rounding) in your data table. The table below is what I get from inputting your x1 and x2. These are the values I will use:

       x1   x2     d
[1,] 1.37 1.68 -0.31
[2,] 2.18 2.99 -0.81
[3,] 1.16 3.24 -2.08
[4,] 3.60 3.08  0.52
[5,] 2.33 2.19  0.14

Sample means and medians behave differently. The reason there needs to be a discussion here is that sample means and sample medians behave in substantially different ways.

Means: If $D_i = X_{1i} - X_{2i},$ then $\bar D = \bar X_1 - \bar X_2,$ where bars designate sample means.

Medians: However, as for your data, one may have $\tilde D \ne \tilde X_1 - \tilde X_2,$ where tildes designate sample medians.

Paired Wilcoxon test. The point made in your link is that the paired Wilcoxon test is a essentially a one-sample signed-rank test on differences.

Thus, you get the same results from the following two tests involving medians. (I'm using R.)

One-sample Wilcoxon test on differences.

wilcox.test(d)

    Wilcoxon signed rank test

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

Paired Wilcoxon test.

wilcox.test(x1, x2, paired=T)  # computes differences first

        Wilcoxon signed rank test

data:  x1 and x2
V = 4, p-value = 0.4375
alternative hypothesis: true location shift is not equal to 0

Incorrect procedure: If you forget the parameter 'paired=T' in the paired test, then R does a Mann-Whitney-Wilcoxon (rank-sum) two-sample test. The P-value is not enormously different, but it should be clear that the test below is not the paired test.

wilcox.test(x1, x2)  # TWO-sample test, NOT PAIRED

        Wilcoxon rank sum test

data:  x1 and x2
W = 8, p-value = 0.4206
alternative hypothesis: true location shift is not equal to 0

Graphical presentation of paired data. For much the same reasons, if you want to show a boxplot for paired data, you must make a single boxplot of differences (as at left), not two separate boxplots of for Before and After. (In showing boxplots, I am assuming that your actual data have more than five subjects. It is unusual to make boxplots of as few as five observations.)

enter image description here

Confusion results from making separate stripcharts (dotplots) of scores Before and After because the plot does not show which Before values are paired with which After values.

enter image description here

You might try connecting data points to show pairs.

enter image description here

Note: For only five subjects, as in the data you show in your Question, the nonparametric Wilcoxon signed rank test would not show a significant result unless all five differences have the same sign.

$\endgroup$
3
  • $\begingroup$ Your answer greatly clarifies what the author (that I cited in my question) was referring to. If I was to use the nonparametric Wilcoxon signed rank test, all would be clear now. However, if I was to use a nonparametric bootstrap hypothesis test, it seems like both options are valid, right? (Difference in medians or median difference). Note that not only in case of the median difference but also in case of the difference of medians, I can account for pairs: in the difference of medians, I'd resample the id and then compute the difference of medians based on the corresponding x1 and `x2. $\endgroup$
    – jollycat
    Apr 6, 2020 at 9:03
  • $\begingroup$ If I were using a resampling procedure, I would resample differences. $\endgroup$
    – BruceET
    Apr 6, 2020 at 9:12
  • $\begingroup$ What would be your motivation to do so? $\endgroup$
    – jollycat
    Apr 6, 2020 at 9:13

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.