简体   繁体   中英

R: empirical version of pnorm() and qnorm()?

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.

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

'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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM