# Re: [R] how to compute the inverse percentile of a given observation w.r.t. a reference distribution

From: David Winsemius <dwinsemius_at_comcast.net>
Date: Wed, 25 May 2011 18:00:37 -0400

On May 25, 2011, at 5:50 PM, Dennis Murphy wrote:

> Hi:
>
> On Wed, May 25, 2011 at 12:42 PM, rudi <rudi.strasser@gmail.com>
> wrote:
>> Hi,
>>
>> can anyone help me to figure out how to compute the percentile of an
>> individual observation with respect to a reference distribution.
>>
>> What I mean is. Let's assume I have a vector consisting of 10 numbers
>> {3,5,8,1,9,5,4,3,5.5,7} and I want figure out what percentile the
>> number 4.9 corresponds to. I failed to find any reference to such a
>> function, although I would assume this must frequently be necessary.
>
> The simple answer is, I believe,
>
> x <- c(3,5,8,1,9,5,4,3,5.5,7)

ecdf(x)(4.9)
>  0.4

ecdf returns a function, so why not use it as such? It is also linked from the quantile help page where it is called the "inverse of quantile".

```--
David.

> plot(ecdf(x))

> sum(x <= 4.9)/length(x)
>  0.4
>

(Somewhat more complicated than necessary.)

> This would correspond to the empirical cumulative distribution

> function (ecdf) to which Jorge alluded.
>
> HTH,
> Dennis
>>
>> Thanks in advance for you help.

David Winsemius, MD
West Hartford, CT

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help