Tell me more ×
Cross Validated is a question and answer site for statisticians, data analysts, data miners and data visualization experts. It's 100% free, no registration required.

I have to find a 95% c.i. on the median and other percentiles. I don't know how to approach this. Any help appreciated. I mainly use R as a programming tool.

share|improve this question

3 Answers

up vote 10 down vote accepted

Here is an illustration on a classical R dataset:

> x=faithful$waiting
> bootmed=apply(matrix(sample(x,rep=TRUE,10^4*length(x)),nrow=10^4),1,median)
> quantile(bootmed,c(.025,0.975))
2.5% 97.5% 
 73.5    77 

which gives a (73.5,77) confidence interval on the median.

(Note: Corrected version, thanks to John. I used $10^3$ in the nrow earlier, which led to the confusion!)

share|improve this answer
3  
Seems suspiciously narrow to me. Using functions from library(boot) appears to confirm this: > boot.ci(boot(x,function(x,i) median(x[i]), R=1000)) Intervals : Level Normal Basic 95% (74.42, 78.22 ) (75.00, 78.49 ) Level Percentile BCa 95% (73.51, 77.00 ) (73.00, 77.00 ) – onestop Jan 15 '12 at 15:13
1  
You are right, sorry about the mistake! – Xi'an Jan 15 '12 at 17:10
1  
you're welcome Xi'an... As an aside, I always prefer to set the original N value in the matrix because that's a constant across various bootstrap sizes I might make. So, I would typically have said ncol = length(x). I find there's less chance for error that way. – John Jan 15 '12 at 23:44
Thank you for giving an example, it was very helpful. – dominic999 Jan 16 '12 at 22:41

Check out bootstrap resampling. Search R help for the boot function. Depending on your data with resampling you can estimate confidence intervals for just about anything.

share|improve this answer
4  
Yes, bootstrap would be my first suggestion as well. – Xi'an Jan 15 '12 at 7:47
Agree. This is the best approach. Underused in the biomedical sciences, in my opinion. – pmgjones Jan 15 '12 at 13:41
3  
Consider looking into the smoothed bootstrap for estimating population quantiles as the conventional boostrap seems to have problems in that case - references can be found in this pdf. If you were just interested in the theoretical Median, the Hodges-Lehman estimator can be used - as provided by, e.g., R's wilcox.test(..., conf.int=TRUE) function. – caracal Jan 15 '12 at 19:50

Another approach is based on quantiles of the binomial distribution.
e.g.:

> x=faithful$waiting
> sort(x)[qbinom(c(.025,.975), length(x), 0.5)]
[1] 73 77
share|improve this answer
I like the simplicity of this one... Results are close to the bootstrap method. – dominic999 Jan 16 '12 at 20:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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