# How to find the minimum range(start/end) which covers 95% of items in a numerical list?

So its like saying 95% of the items sold in this website costs between 25 - $150. While some items might cost less than$25 and other items might cost more than \$150.

Is there a way to find this? Is this something related to CI - confidence Interval?

-
What do you mean by 'the minimum range'? –  Macro Mar 22 '12 at 19:24
See Reference range on Wikipedia. –  onestop Mar 22 '12 at 20:08
What data or related information do you have to begin with? –  whuber Mar 22 '12 at 20:14
Weakly related: stats.stackexchange.com/questions/24588/… –  Henry Mar 22 '12 at 21:52
This sounds like a homework question. It has to do with standard deviation which is used to calculate confidence intervals. I would say more but in the interest of facilitating your learning I'll direct you to the wikipedia page on standard deviation instead. en.wikipedia.org/wiki/Standard_deviation I'd be happy to discuss this further but please read that, make an attempt at solving the problem, and then ask some intelligent questions and we can go from there. –  Will Mar 23 '12 at 2:30
show 3 more comments

## 1 Answer

If you mean the narrowest range then something like this would do it

set.seed(1)
dat        <- rnorm(1000000)
ordereddat <- sort(dat)
width      <- ceiling(length(ordereddat) * 0.95)
difdat     <- diff(ordereddat, lag = width)
min        <- which(difdat == min(difdat))
c(ordereddat[min[1]] , ordereddat[min[1] + width])

producing

[1] -1.962899  1.961126

If you want as many items above as below then there is the simple but slightly wider

> c(quantile(dat, 0.025),  quantile(dat, 0.975))
2.5%     97.5%
-1.960232  1.964565
-
i think c(quantile(dat, 0.025), quantile(dat, 0.975)) fits what i was looking for. thank you –  Prabhu M Mar 23 '12 at 4:03
add comment