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
2010-06-23 13:37:11
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
2010-06-23 13:43:44
+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
2010-06-23 13:42:03
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
2010-06-23 14:04:18
+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
2010-06-23 13:49:49