我试图使用二元正态分布找到P(X + + 0.5 但我不确定下一步该去哪,或者我是否走在正确的轨道上。 library("mvtnorm")
meanVector <- c(9,10)
coV <- matrix(c(3, 2, 2, 5), nrow=2)
biv <- rmvnorm(50, mean=meanVector, sigma=coV)
geneA <- mean(biv[,1])
geneB <- mean(biv[,2])
答案 0 :(得分:1)
如果您想通过模拟估算此值,则必须多次进行实验。在这里,我们进行了50次试验,我们模拟了2000次。注意,P(Xbar + 0.5&lt; Ybar)可以重写为P(Xbar + 0.5 - Ybar&lt; 0):
set.seed(123)
sims <- 2000
out <- replicate(sims, {
biv <- rmvnorm(50, mean=meanVector, sigma=coV)
geneA <- mean(biv[,1])
geneB <- mean(biv[,2])
geneA + 0.5 - geneB
})
我们可以绘制这个数量的分布:
plot(density(out), main = expression(bar(X) + 0.5 - bar(Y)))
dout <- density(out)
dout <- cbind(dout$x, dout$y)[dout$x < 0, ]
dout <- rbind(dout, c(0, 0))
polygon(dout[,1], dout[,2], col = "grey", lty = 0)
abline(v = 0, col = "red")
我们对阴影区域感兴趣。根据我们的模拟值,我们计算模拟的比例,其中Xbar + 0.5 - Ybar&lt; 0:
mean(out < 0)
# [1] 0.9585
接近P的分析值(Xbar +0.5
答案 1 :(得分:0)
试试这个:
meanVector <- c(9,10)
coV <- matrix(c(3, 2, 2, 5), nrow=2)
n <- 10000 # choose a large number
prob <- sum(replicate(n, {
biv <- rmvnorm(50, mean=meanVector, sigma=coV)
geneA <- mean(biv[,1])
geneB <- mean(biv[,2])
geneA + 0.5 < geneB})) / n
prob
[1] 0.9592