I am trying to calculate the difference between medians with a 95%CI for continuous variables of independent samples. I need to do this for group A versus group B and group A versus group C. I made two datasets, sample 1 and sample 2:
My descriptives are:
Sample 1
- Group A, var1: median 1.5 (20 subjects, #10 ="1" and #11="2")
- Group B, var1: median 3 (35 subjects, #18 ="3")
Sample 2
- Group A, var1: median 1.5 (20 subjects, #10 ="1" and #11="2")
- Group C, var1: median 2 (18 subjects, #9 ="2" and #10="2")
Observations:
- Group A, var1: 1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,3,3,6,8,8
- Group B, var1: 1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,3,3,3,3,4,4,4,4,5,5,6,6,7,7,7,8,9,9,18,20
- Group C, var1: 1,1,1,1,1,1,2,2,2,2,3,4,5,6,7,7,7,20
I tried to use the median_test from the "Coin" package, but it returns a "difference in location" of 0.999 for sample 1, and 1.0 for sample 2. The median difference is 1.5 (sample 1) and 2.5(sample 2) though, and I don't know how to make these results match.
For sample 1
install.packages("coin"') ; library("coin")
median_test(formula = var1 ~ Group, data = dat2, ties.method = "average-scores", mid.score = "0.5",conf.int = TRUE, conf.level = 0.95)
Output
Asymptotic Two-Sample Brown-Mood Median Test
data: var1 by Group(B, A)
Z = 2.3951, p-value = 0.01662
alternative hypothesis: true mu is not equal to 0
95 percent confidence interval: -5.996509e-05 2.000034e+00
sample estimates: difference in location 0.9999581
For sample 2
median_test(formula = Opnameduur ~ Sedatie, data = dat, ties.method = "average-scores", mid.score = "0.5", conf.int = TRUE, conf.level = 0.95)
Output
Asymptotic Two-Sample Brown-Mood Median Test
data: Opnameduur by Sedatie (morfine, ketamine)
Z = 1.2606, p-value = 0.2074
alternative hypothesis: true mu is not equal to 0
95 percent confidence interval: 2.775156e-07 3.999948e+00
sample estimates: difference in location 1.000018
I have tried adjusting the ties.method argument to "average-scores", and adjusted mid.score to "0.5", but this does not change the different estimate.
My guess is that it has to do with the mid-ranks vs average-score calculation of the medians.
My questions are:
- Is the "difference in location" is really the difference between the medians?
- Is there a way to adjust this test so it uses the correct median? Or a different test that works better?
- Or is there a way to adjust the way the median is calculated in the descriptives (with some kind of mid-ranks argument)?
Thank you!