- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如果我已经知道特定的百分位数,我会尝试了解如何生成正态分布。
一位用户对类似问题 (link here) 给出了非常全面的答案,但是当我尝试使用现有数据对其进行测试时,方差太大了。
我是怎么做到的:
x <- c(5,8,11)
PercRank <- c(2.1, 51.1, 98.8)
例如,PercRank = 2.1 表示 2.1% 的数据的值/分数 <= 5(x 的第一个值)。同样,PercRank = 51.1 表示 51.1% 的数据具有值/分数 <= 8。
我按照这个link中的方法.这是我的代码:
cum.p <- c(2.1, 51.1, 98.8)/100
prob <- c( cum.p[1], diff(cum.p), .01)
x <- c(5,8,11)
freq <- 1000 # final output size that we want
# Extreme values beyond x (to sample)
init <- -(abs(min(x)) + 1)
fin <- abs(max(x)) + 1
ival <- c(init, x, fin) # generate the sequence to take pairs from
len <- 100 # sequence of each pair
s <- sapply(2:length(ival), function(i) {
seq(ival[i-1], ival[i], length.out=len)
})
# sample from s, total of 10000 values with probabilities calculated above
out <- sample(s, freq, prob=rep(prob, each=len), replace = T)
quantile(out, cum.p)
# 2% 51.1% 98.8%
# 5 8 11
c(mean(out), sd(out))
# [1] 7.834401 2.214227
所有这些都来自评论 ( linked ),到目前为止一切顺利。然后我尝试检查生成的正态分布与我的拟合值的配合情况:
data.frame(sort(rnorm(1000, mean=mean(out), sd=sd(out))))
...
# 988 13.000904
# 989 13.028881
# 990 13.076649
...
# 1000 14.567080
我很担心,因为第 988 个值(例如,1000 个样本中的 98.8%)是 13.000904,而我为 98.8% 百分位数拟合的值是 11.0。
我多次重新生成分布,方差一直比需要的大。
我被难住了。如果有人能告诉我一种使方差更准确的方法,我将不胜感激。或者,这是不可避免的吗?
(我第一次在这里发帖,如果我违反了规则,我深表歉意 - 如果需要,我可以说得更清楚。)
最佳答案
您为什么不将其视为优化问题?
x <- c(5,8,11)
PercRank <- c(2.1, 51.1, 98.8)
fun <- function(par, pq) {
sum((log(pq[,1]/100)-pnorm(pq[,2], mean=par[1], sd=par[2], log.p=TRUE))^2)
}
par.estimates <- optim(c(0,1), fn=fun, pq=cbind(PercRank, x))
pnorm(11, par.estimates[[1]][1], par.estimates[[1]][2])
#[1] 0.9816948
结果似乎是合理的,但与 q=11 的预期值存在一些差异。但是,我怀疑这是您的数据的问题(例如,由于四舍五入),因为以下方法运行良好:
PercRank <- pnorm(x, 8, 2)*100
par.estimates <- optim(c(0,1), fn=fun, pq=cbind(PercRank, x))
par.estimates[[1]]
#[1] 7.999774 1.999953
当然,对于这个特定问题可能有更好的优化器。
关于r - 从已知百分位数生成正态分布,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19996661/
我有一个数字列表,其中包含这些数字的样本平均值和标准差。现在我正在尝试找出平均值+-SD、平均值+-2SD 和平均值+-3SD 中的数字。例如,在mean+-SD部分,我编写了这样的代码: ND1 =
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: erf(x) and math.h Best library for statistics in C++?
我正在尝试模拟球迷到达体育场。系统本身,我相信不会有问题,但是,粉丝的到来是一个正态分布。 我的问题是: 我有一个特定的到达时间,比如 100 分钟和 1000 个粉丝,我需要在该分布之后的某个时间生
在 Julia 中,有人实现了正态分布 pdf 或 cdf 来支持任意精度的 BigFloats。 例如,此代码返回 0.0,而实际上这些值应该略有不同。 x = parse(BigFloat, "2
给定具有上限和下限误差的平均值,计算分割正态分布的最佳方法是什么? 到目前为止我已经: from random import choice, gauss def random_split_normal
我希望用户指定分布的范围 delta、sigma 以及它应该产生的随机值的数量。但是在 Iron Python 中生成具有正态分布的随机值的最佳方法是什么?我在 NumPy 中找到了一个可以执行此操作
我的说明:编写一个程序,开始询问用户正态分布的均值 u 和标准差 s(参见 wiki article) 程序然后要求 N,然后要求 N 个值 x。对于每个 x,它都会将 f(x) 写到屏幕上。请注意,
通用的 Accept 拒绝算法和往常一样。 1 从 Unif[0,1] 生成 U 1 ,U 2 ,U 3 2 X ← −log(U 1 ) 3 if U 2 > exp(−0.5(X − 1) 2 )
我需要计算两条曲线之间的面积。我有很多数据,所以我想以编程方式进行。 基本上,我总是有 2 个正态分布,根据平均值和标准差计算得出。然后我想计算它们相交的程度。这是一个 example我的意思,还有一
我想知道 JavaScript 函数 Math.random 是否使用正态分布(相对于均匀分布)。 如果不是,我怎样才能得到使用正态分布的数字?对于创建随机正态分布数字的算法,我尚未在 Interne
我想在 d3.js 中创建正态分布图(钟形曲线)。 像这样[ http://statwiki.ucdavis.edu/@api/deki/files/73/a9f781e1b0891ceedd50cd
我的教授正在模拟客户到达银行的情况。它表示客户到达时遵循均值 3.5 和标准偏差 1.3 的正态分布。 问题是我很难理解为什么使用这段代码。我相信他提供的代码正在接收一个流、平均值和标准差来生成随机数
我正在生成一些随机数并出现可疑行为。这是我的代码: // initialized earlier... in the constructor of a class boost::mt1
用 ruby 生成正态分布随机数的代码是什么? (注意:我回答了我自己的问题,但我会等几天再接受,看看是否有人有更好的答案。) 编辑: 为此,我查看了两次搜索产生的 SO 上的所有页面: +“正态
我尝试编写 R 代码来查找 mu s.t. 的值。正态分布满足概率 P(N(mu, 1)>1.96)=0.95 (即 P(Z>1.96)=0.95 其中 Z~ N(mu, 1) 和 mu 是我想要得到
我是一名优秀的程序员,十分优秀!