简体   繁体   English

使用R的概率样本估计

[英]sample estimate of probability using R

Suppose I have a random sample of 100 observations from a population with distribution Y=X^2, where X is normal. 假设我从分布Y = X ^ 2的总体中随机抽取100个观测值,其中X为正态。 How do I calculate the sample estimate of P(Y<=2) using R? 如何使用R计算P(Y <= 2)的样本估计值? Here P() denotes probability. 在此,P()表示概率。 Does the following code help? 以下代码有帮助吗?

X=rnorm(100)
Y=X^2
prob(Y<=2)

Thanks beforehand 预先感谢

If y = x^2 , then P(y <= 2) = P(x^2 <= 2) = P(x <= sqrt(2)) 如果y = x^2 ,则P(y <= 2) = P(x^2 <= 2) = P(x <= sqrt(2))

So, the answer is: 因此,答案是:

pnorm(sqrt(2)) - pnorm(-sqrt(2))
# [1] 0.8427008

Thanks to @markdly the required code is sum(Y<=2)/length(Y) 感谢@markdly,所需的代码为sum(Y <= 2)/ length(Y)

This calculates the probability that the sample observations are less than or equal to 2, which varies with sample. 这将计算样本观察值小于或等于2的概率,该概率随样本而变化。 The above answer given by @akond, which basically calculates the exact probability could also be derived from pchisq(2,1) @akond给出的上述答案基本上可以计算出准确的概率,也可以从pchisq(2,1)得出

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

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