# How to construct a 95% confidence interval of the difference between medians?

My problem: parallel group randomized trial having a very right-skewed distribution of the primary outcome. I do not want to assume normality and use normal-based 95% CIs (i.e. using 1.96 X SE).

I am comfortable expressing the measure of central tendency as the median, but my question is then how to construct a 95% CI of the difference in medians between the two groups.

The first thing that comes to mind is bootstrapping (resample with replacement, determine median in each the two groups and subtract one from the other, repeat 1000 times, and use the Bias-corrected 95% CI). Is this the correct approach? Any other suggestions?

• That was the first thing that came to my mind too. How big a sample do you have? – jbowman Apr 24 '12 at 16:01
• 40 people in each of two groups = 80 total. – pmgjones Apr 24 '12 at 17:21
• You might look into the nonparametric confidence interval and estimator for the difference of location parameters based on the Hodges-Lehmann estimator. As explained in the help page for R's wilcox.test() (under Details), this is closely related to the difference in medians, but not quite the same. – caracal Apr 24 '12 at 17:36
• With regards to bootstrapping the median, it might be worthwhile to read about the smoothed bootstrap. – caracal Apr 24 '12 at 17:47
• @caracal : This is a good point. Both the usual or smoothed bootstrap have correct asymptotic coverage, but the coverage probability of the smoothed bootstrap converges at a slightly faster rate. If I recall correctly, $|P(m \in \hat{I}_n) - 0.95| = O(n^{-1/3})$ for the usual bootstrap, and $O(n^{-2/5})$ for the smoothed bootstrap. There is a brief discussion of this with further references in Quantile Regression by Koenker (2005). – paul Apr 25 '12 at 19:05

The bootstrap procedure that you describe should be valid. However, it's important to keep in mind that, like normal-based 95% CI, a bootstrap confidence interval is only guaranteed to have correct coverage asymptotically. One nice thing about working with the median or other quantiles is that you can construct exact finite sample confidence intervals under very weak assumptions. The basic idea is that under the null that median of $y$ is $m$, the indicator for $y < m$ is a Bernoulli 0.5 random variable. You can use this observation to create a test statistic with a known finite sample distribution. See Chernozhukov, Hansen, Jansson (2009) for more details.
• @pmgjones: A 95% confidence interval, $\hat{I}_n$, for some parameter $m$ is such that $P(m \in \hat{I}_n) = 0.95$ for all possible $m$ (or really all possible data generating processes). I wrote $\hat{I}_n$ to emphasize that the interval is some function of your sample. For the bootstrap or normal-based confidence interval, it is not true that $P(m \in \hat{I}_n) = 0.95$ (except for very special data generating processes). However, you can show that $\lim_{n \to \infty} P(m \in \hat{I}_n) = 0.95$. This is what I meant by saying that the bootstrap is only valid asymptotically. – paul Apr 25 '12 at 18:52