[R] CI on median

Frank E Harrell Jr feh3k at spamcop.net
Sat Sep 27 08:39:40 CEST 2003

On Sat, 27 Sep 2003 13:25:57 +0200
Troels Ring <tring at gvdnet.dk> wrote:

> Dear friends, I'm probably wrong but is there anything better than 
> bootstrap to get a confidence interval of the median from a population with 
> unspecified distribution ?
> Best wishes
> Troels Ring, Aalborg, Denmark

The bootstrap doesn't work perfectly for the median.  Standard nonparametric statistics texts provide a distribution-free CI for the median, like:

medianCI <- function(y) {
    y <- sort(y[!is.na(y)])
    n <- length(y)
    if(n < 4) return(c(NA,NA))
    r <- pmin(qbinom(c(.025,.975), n, .5) + 1, n)  ## Exact 0.95 C.L.

In an upcoming release of the Hmisc package you can also get the Harrell-Davis distribution-free estimator of the median which is slightly more efficient than the traditional estimator, for small samples.  A new hdquantile function provides an estimate of the standard error for this estimator.

Frank E Harrell Jr    Professor and Chair            School of Medicine
                      Department of Biostatistics    Vanderbilt University

More information about the R-help mailing list