简体   繁体   中英

Probability from bivariate normal distribution

I am trying to find the probability that P(X̄+0.5 < Ybar) using a bivariate normal distribution. X has a mean of 9 and variance of 3, Y has a mean of 10, and a variance of 5, and their covariance is 2, with a trial of 50 independent measurements. What I have so far is:

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])

But I am not sure where to go next, or if I am even on the right track.

If you want to estimate this value by simulation, you'll have to do the experiment many times. Here we have an experiment with 50 trials, which we simulate 2000 times. Note that P(Xbar + 0.5 < Ybar) can be rewritten as P(Xbar + 0.5 - Ybar < 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
})

We can plot the distribution of this quantity:

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")

在此处输入图片说明

where we are interested in the shaded area. From our simulated values, we compute the proportion of simulations where Xbar + 0.5 - Ybar < 0:

mean(out < 0)
# [1] 0.9585

which is close to the analytic value of P(Xbar +0.5 < Ybar).

Try this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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