tags:

views:

80

answers:

3

I have a normalization method that uses the normal distribution functions pnorm() and qnorm(). I want to alter my logic so that I can use empirical distributions instead of assuming normality. I've used ecdf() to calculate the empirical cumulative distributions but then realized I was beginning to write a function that basically was the p and q versions of the empirical. Is there a simpler way to do this? Maybe a package with pecdf() and qecdf()? I hate reinventing the wheel.

+1  A: 

Isn't that exactly what bootstrap p-values do?

If so, keep a vector, sort, and read out at the appropriate position (i.e. 500 for 5% on 10k reptitions). There are some subtle issue with with positions to pick as e.g. help(quantile) discusses under 'Types'.

Dirk Eddelbuettel
I think you are right. I just could not think of what function would do this. Thanks for the fast response. I was able to ask a question and get 2 answers before I got off the train. Fantastic.
JD Long
+8  A: 

You can use the quantile and ecdf functions to get qecdf and pecdf, respectively:

x <- rnorm(20)
quantile(x, 0.3, type=1) #30th percentile
Fx <- ecdf(x)
Fx(0.1)  # cdf at 0.1
Aniko
yes! Thank you. I kept thinking "this has to be pretty simple" but I was having trouble coming up with an answer. Thank you.
JD Long
+2  A: 

'emulating' pnorm for an empirical distribution with ecdf:

> set.seed(42)
> x <- ecdf(rnorm(1000))
> x(0)
[1] 0.515
> pnorm(0)
[1] 0.5
FloE