简体   繁体   English

R:pnorm()和qnorm()的经验版本?

[英]R: empirical version of pnorm() and qnorm()?

I have a normalization method that uses the normal distribution functions pnorm() and qnorm(). 我有一个使用正态分布函数pnorm()和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. 我用ecdf()来计算经验累积分布但后来意识到我开始写一个基本上是经验的p和q版本的函数。 Is there a simpler way to do this? 有更简单的方法吗? Maybe a package with pecdf() and qecdf()? 也许包含pecdf()和qecdf()的包? I hate reinventing the wheel. 我讨厌重新发明轮子。

You can use the quantile and ecdf functions to get qecdf and pecdf , respectively: 您可以使用quantileecdf函数分别获取qecdfpecdf

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: 使用ecdf“模拟”经验分布的pnorm:

> 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? 这不正是引导p值的作用吗?

If so, keep a vector, sort, and read out at the appropriate position (ie 500 for 5% on 10k reptitions). 如果是这样的话,请保持一个向量,排序并在适当的位置读出(即10k的5%为500%)。 There are some subtle issue with with positions to pick as eg help(quantile) discusses under 'Types'. 有一些微妙的问题需要选择,例如help(quantile)在“类型”下讨论。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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