问题描述
我想知道如何让 R 告诉我 SD(作为 R 内置的 qnorm() 中的一个参数)正态分布的 95% 限制值是否已知?
I was wondering how I could have R tell me the SD (as an argument in the qnorm() built in R) for a normal distribution whose 95% limit values are already known?
举个例子,我知道我的法线的两个 95% 极限值分别是 158 和 168.因此,在下面的 R 代码 SD 中显示为x".如果y"(这个简单的qnorm()函数的答案)需要是(158, 168),那么 R可以告诉我x 应该是什么?
As an example, I know the two 95% limit values for my normal are 158, and 168, respectively. So, in the below R code SD is shown as "x". If "y" (the answer of this simple qnorm() function) needs to be (158, 168), then can R tell me what should be x?
y <- qnorm(c(.025,.975), 163, x)
推荐答案
正态分布的一般过程
假设我们有一个正态分布 X ~ N(mu, sigma)
,具有未知的均值 mu
和未知的标准偏差 sigma
.我们的目标是求解 mu
和 sigma
,给定两个分位数方程:
A general procedure for Normal distribution
Suppose we have a Normal distribution X ~ N(mu, sigma)
, with unknown mean mu
and unknown standard deviation sigma
. And we aim to solve for mu
and sigma
, given two quantile equations:
Pr(X < q1) = alpha1
Pr(X < q2) = alpha2
我们考虑标准化:Z = (X - mu)/sigma
,所以
We consider standardization: Z = (X - mu) / sigma
, so that
Pr(Z < (q1 - mu) / sigma) = alpha1
Pr(Z < (q2 - mu) / sigma) = alpha2
换句话说,
(q1 - mu) / sigma = qnorm(alpha1)
(q2 - mu) / sigma = qnorm(alpha2)
RHS 是明确已知的,我们定义 beta1 = qnorm(alpha1)
, beta2 = qnorm(alpha2)
.现在,上面简化为 2 个线性方程组:
The RHS is explicitly known, and we define beta1 = qnorm(alpha1)
, beta2 = qnorm(alpha2)
. Now, the above simplifies to a system of 2 linear equations:
mu + beta1 * sigma = q1
mu + beta2 * sigma = q2
这个系统有系数矩阵:
1 beta1
1 beta2
具有行列式 beta2 - beta1
.奇点的唯一情况是beta2 = beta1
.只要系统是非奇异的,我们就可以使用solve
来求解mu
和sigma
.
with determinant beta2 - beta1
. The only situation for singularity is beta2 = beta1
. As long as the system is non-singular, we can use solve
to solve for mu
and sigma
.
想想奇点情况意味着什么.qnorm
对于正态分布是严格单调的.所以beta1 = beta2
和alpha1 = alpha2
是一样的.但这很容易避免,因为它在您的规范下,所以在下面我不会检查奇异性.
Think about what the singularity situation means. qnorm
is strictly monotone for Normal distribution. So beta1 = beta2
is as same as alpha1 = alpha2
. But this can be easily avoided as it is under your specification, so in the following I will not check singularity.
将上面总结成一个估计函数:
Wrap up above into an estimation function:
est <- function(q, alpha) {
beta <- qnorm(alpha)
setNames(solve(cbind(1, beta), q), c("mu", "sigma"))
}
让我们测试一下:
x <- est(c(158, 168), c(0.025, 0.975))
# mu sigma
#163.000000 2.551067
## verification
qnorm(c(0.025, 0.975), x[1], x[2])
# [1] 158 168
我们也可以随意:
We can also do something arbitrary:
x <- est(c(1, 5), c(0.1, 0.4))
# mu sigma
#5.985590 3.890277
## verification
qnorm(c(0.1, 0.4), x[1], x[2])
# [1] 1 5
这篇关于根据分位数信息确定正态分布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!