Say I have a frequency density data, for example

1,2,3,3,4,5,5,6,6,6,7,8,8,8,9,10 and then I compute the frequency of each number. Than I would like to know within what range 95%, 50%, and 10% of the data falls into. I imagine if I calculate 10% it will give me multiple ranges. What are these statistics called and how do I calculate them?

Basically I would like to say that 95% of the data is within 5-7 or that 50% is within 3-9. I guess that the distribution of the data would change how to go about this. What I have done so far is to use the quantile function in r and specify .025 and .975, and .25/.75 (I realize these are quartiles).

  • $\begingroup$ Create a histogram and then start expanding the range from the mode, in either right or left direction(on x-axis) based on which has higher frequency.This way you should get the shortest-interval which contains P% of data. You can continue expanding till you cover at-least P% of data. $\endgroup$ Jan 16, 2017 at 14:04
  • $\begingroup$ @Ujjwal That algorithm doesn't sound like it will work correctly. But there is a very simple $O(n\log(n))$ method. Start by converting the percentage into a count $k$ of values that the interval should cover. Sort the data $x_1\le x_2\le \cdots \le x_n$. Compute the $n-k+1$ ranges $x_k-x_1, x_{k+1}-x_2,\ldots, x_n-x_{n-k+1}$. Pick the smallest of them. $\endgroup$
    – whuber
    Jan 16, 2017 at 17:22
  • $\begingroup$ @whuber I am not familiar with any of the notation you have used, how can I interpret it? $\endgroup$ Jan 17, 2017 at 11:47
  • $\begingroup$ @UjjwalKumar I do not think your algorithm would work because you are assuming a normal distribution $\endgroup$ Jan 17, 2017 at 11:47
  • $\begingroup$ True, it won't work for every case, but the algorithm doesn't assumes a normal distribution, rather a uni-modal distribution I think. $\endgroup$ Jan 17, 2017 at 11:49


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.