# Percentile of list of numbers

Suppose that I have a list of numbers, say [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]. These numbers are realisations of a random variable $$X$$ whose distribution I am interested in.

Suppose I want to estimate the 5th percentile of this distribution (to form a confidence interval for $$X$$). Intuitively, I would take the lowest number (i.e. 1) as my estimate for this since 90% of the numbers are higher, and 0% are lower (which in some sense 'averages out' to the desired 5%!) However, when I use numpy.percentile (with the default setting), it suggests an estimate of 1.45. Which estimate is better, and why?

Update: To clarify, my goal is to estimate the interval $$I=[x,y]$$ with $$y > x$$ such that $$\mathbb{P}(X \in I)=0.95$$. The numbers $$x$$ and $$y$$ are the 5th and 95th percentiles respectively of the distribution of $$X$$.

• Could you please explain how an estimate of the 5th percentile would form part of a confidence interval for any property of $X$? What property specifically? Only then could we possibly justify any opinions about what procedure, if any, might be better than another one.
– whuber
Apr 18, 2023 at 15:29
• You might see the documentation for numpy.percentile in Python. (I assume that's what you're using.) There are several options for methods that it uses to calculate percentiles. numpy.org/doc/stable/reference/generated/numpy.percentile.html Apr 19, 2023 at 11:18
• If my interpretation is correct, you haven't a prayer of obtaining a nonparametric 95% tolerance interval using a sample of size 10, for what I hope are intuitively obvious reasons. But if you make parametric assumptions about the distribution of $X,$ you can obtain such tolerance intervals. They tend to be very uncertain and depend heavily on the correctness of those parametric assumptions. So, if you really are looking for a tolerance interval of some sort, please edit your post to make that clear, because you definitely are not just computing a percentile of the data!
– whuber
Apr 19, 2023 at 15:20
• That's problematic when you are estimating an interval. Moreover, most such criteria make no sense in a nonparametric setting or just cannot be applied. That's why disclosing additional details about your specific problem can make the difference between a question that is too broad and one that has a clear, good answer. Right now, especially after your last comment, it's not even evident what your question is.
– whuber
Apr 20, 2023 at 14:35
• @Sal I believe the bootstrap estimate will be identical to the usual nonparametric estimate based on order statistics, depending on which form of tolerance interval is needed. A TI can also be conceived of as a pair of confidence limits for the endpoint percentiles and consequently similar specification issues apply, such as whether you want upper, lower, or two-sided limits, whether you want them to be symmetric in probability, and so on.
– whuber
Apr 20, 2023 at 14:52

As pointed out by @Sal Mangiafico, some helpful documentation on numpy.percentile is provided here, which in turn draws on the useful paper:

R. J. Hyndman and Y. Fan, “Sample quantiles in statistical packages,” The American Statistician, 50(4), pp. 361-365, 1996

As explained in the paper, various approaches to the problem are possible. To illustrate a few in the context of this example:

1. The inverted CDF method produces an estimate of $$1$$, which matches up with how I would have naively approached the problem.
2. The linear method (the default) views our 10 draws as dividing the space into $$9$$ intervals, each with width $$1/9 = 0.\dot{1}$$. Since we want the 5th percentile (0.05), we want the first interval, which ranges from $$1$$ to $$2$$. How far along the interval should we be? Using linear interpolation, it's $$1 + 0.05/0.\dot{1} = 1.45$$.
3. Hyndman and Fan (1996) recommend the median unbiased method when the sample distribution function is unknown. In this example, this method also yields an estimate of 1.

I believe that all methods yields identical estimates when the sample size goes to infinity.

• This answer makes it look like you are trying to re-ask the question at stats.stackexchange.com/questions/178578. Would that be the case? If so, that thread has a good answer. You can find out more by searching our site for quantile Hyndman Fan.
– whuber
Apr 20, 2023 at 15:01
• Thanks for the link, which is useful. The questions are somewhat different since that poster was not explicitly trying to estimate the interval $I$. However, the answer is still helpful (although not as helpful as reading the Hyndman Fan paper itself!) Apr 20, 2023 at 15:08
• But your answer doesn't really cover estimation in any meaningful way: it--as well as the title of your question--focuses on computing percentiles of "lists of numbers."
– whuber
Apr 20, 2023 at 15:11
• I didn't go into the properties of the various estimators since they are already in the paper. However, I agree that a non-technical write up of these properties would be nice. Apr 20, 2023 at 15:13