tarun14110
tarun14110

Reputation: 990

90% confidence interval around the median in using DescTools::medianCI()

I need to get a 90% confidence interval around the median.

x <- c(251, 108, 27, 18, 195, 82, 222, 38, 81, 181, 140, 21, 43, 47, 15, 37, 46, 107, 19, 178, 95, 130, 60, 34, 48, 219, 338, 78, 117, 62, 40, 52)
MedianCI(x, conf.level=0.9)

the result is

median lwr.ci upr.ci 
 70     46    108  
attr(,"conf.level") [1] 0.9498975

It generates an interval for 0.949 level, but I want 0.9. What would be the right way to do it? The correct answer should be (70, 47, 108).

Upvotes: 0

Views: 740

Answers (1)

Ben Bolker
Ben Bolker

Reputation: 226182

There are two main issues here.

  1. The method given in the book is approximate. As the author states, it's probably fine for most large-sample data sets, but it's actually farther from "correct" than the methods implemented by MedianCI

  2. Especially for small data sets, it's unlikely that a confidence interval (however computed) will line up exactly with an observation in the data set: that's why the author says

The results of the equation are rounded up to the next integer and the boundary of the confidence interval is between the two values in the data set.

(It's not clear to me why the results are rounded up for both the lower and the upper CI limit; I would have expected them to be rounded up for the upper limit and down for the lower limit ...)

By giving you the 0.949 confidence interval instead of the 0.9 you asked for, MedianCIis being conservative (the typical definition of the CI being an interval that includes the true value at least x% of the time); confidence level 0.89-0.94 will give you the 0.949 level, while values from 0.79-0.88 will give you the 0.889 level.

If you have follow-up questions about the technical details of my answer, you should probably ask on CrossValidated. I don't know if there's a handy-dandy built-in function in an R package somewhere that implements the approximate method given in the book (although it should take only advanced-beginner R skill to implement; if you want to try it, give it a shot and feel free to ask another question when you get stuck ...)

Upvotes: 2

Related Questions