Distribution empirical in R

3.3k views Asked by At

I have a vector of observations and would like to obtain an empirical p value of each obervation with R. I don't know the underlying distribution, and what I currently do is just

runif(100,0,1000)->ay
quantile(ay)

However, that does not really give me a p-value. How can I obtain a p-value empirically?

2

There are 2 answers

2
user295691 On

I think what you want is the ecdf function. This returns an empirical cumulative distribution function, which you can apply directly

ay <- runif(100)
aycdf <- ecdf(ay)

And then

> aycdf(c(.1, .5, .7))
[1] 0.09 0.51 0.73
5
TBSRounder On

I think this is what you're looking for:

rank(ay)/length(ay)