Let \(X_1,...,X_{10}\sim N(10, 3)\), all independent. Find
\[P(X_1>13)=1-P(X_1<13)\]
1-pnorm(13, 10, 3)
## [1] 0.1586553
\[ \begin{aligned} &E[X_1+X_2] = E[X_1]+E[X_2]=10+10=20\\ &var(X_1+X_2) = var(X_1)+var(X_2)=3^2+3^2=18 \\ &X_1+X_2\sim N(20, \sqrt{18})\\ &P(X_1+X_2>26)=1-P(X_1+X_2<26) = \\ \end{aligned} \]
1-pnorm(26, 20, sqrt(18))
## [1] 0.0786496
\[ \begin{aligned} &E[X_1+..,+ X_{10}] = E[X_1]+..+E[X_{10}]=10*10=100\\ &var(X_1+...+X_{10}) = var(X_1)+...+var(X_{10})=3^2+...+3^2=90 \\ &X_1+...+X_{10}\sim N(100, \sqrt{90})\\ &P(X_1+...+X_{10}>26)=1-P(X_1+...+X_{10}<26) = \\ \end{aligned} \]
1-pnorm(130, 100, sqrt(90))
## [1] 0.0007827011
\((X,Y)\) has a bivariate normal distribution with \(\mu_x=1,\mu_y=2,\sigma_x^2=5,\sigma_y^2=7\) and \(\rho=-0.3\). Find \(E[XY]\).
\[ \begin{aligned} &E[XY] = E\{E[XY|Y\} = E\{YE[X|Y]\} = \\ &E\left\{Y\left[\mu_x+\rho\frac{\sigma_x}{\sigma_y}(Y-\mu_y)\right]\right\} = \\ &E\left\{\mu_xY+\rho\frac{\sigma_x}{\sigma_y}(Y^2-\mu_yY)\right\} = \\ &\mu_xE[Y]+\rho\frac{\sigma_x}{\sigma_y}\left\{E[Y^2]-\mu_yE[Y]\right\} = \\ &\mu_x\mu_y+\rho\frac{\sigma_x}{\sigma_y}\left\{var(Y)+E[Y]^2-\mu_y^2\right\} = \\ &\mu_x\mu_y+\rho\frac{\sigma_x}{\sigma_y}\left\{\sigma_y^2\right\} = \\ &\mu_x\mu_y+\rho \sigma_x\sigma_y = 1\times 2+(-0.3)\sqrt{5\times 7} = 0.225 \end{aligned} \]
library(mvtnorm)
mu=c(1,2)
mux=1;muy=2;sigma2x=5;sigma2y=7;rho=-0.3
A=cbind(c(sigma2x, rho*sqrt(sigma2x*sigma2y)),
c(rho*sqrt(sigma2x*sigma2y), sigma2y))
B=1e5
x=rmvnorm(B, mu, A)
apply(x,2,mean)
## [1] 1.004872 2.000010
apply(x,2,var)
## [1] 4.991178 6.972993
cor(x[,1],x[,2])
## [1] -0.2980986
c(mean(x[,1]*x[,2]), mux*muy+rho*sqrt(sigma2x*sigma2y))
## [1] 0.2511565 0.2251761
Let \((X,Y,Z)\) have a multivariate normal distribution with mean vector \(\pmb{\mu} = \begin{pmatrix} 1&0&1 \\ \end{pmatrix}\) and variance-covariance matrix
\[ \pmb{\Sigma} = \begin{pmatrix} 5 & 2& 0\\ 2 & 7 & 2 \\ 0 & 2 & 10\\ \end{pmatrix} \] Find
\(X\sim N(1, \sqrt{5})\), so \(P(X<3)=\)
pnorm(3, 1, sqrt(5))
## [1] 0.8144533
mu=c(1,0,1)
A=cbind(c(5,2,0), c(2,7,2), c(0,2,10))
B=1e5
x=rmvnorm(B, mu, A)
sum(x[,1]<3)/B
## [1] 0.81482
\(X+Y\) has a normal distribution with \(E[X+Y]=E[X]+E[Y]=1\) and variance
\[var(X+Y)=var(X)+var(Y)+2cov(X,Y)=5+7+2\times 2=16\]
and so
\[P(X+Y<3)\]
pnorm(3, 1, sqrt(16))
## [1] 0.6914625
x1=x[,1]+x[,2]
c(mean(x1), var(x1))
## [1] 0.9828641 15.9014599
sum(x1<3)/B
## [1] 0.6948
\(X+Y+Z\) has a normal distribution with \(E[X+Y+Z]=E[X]+E[Y]+E[Z]=2\) and variance
\[var(X+Y+Z)=\\var(X)+var(Y)+var(Z)+\\2cov(X,Y)+2cov(X,Z)+2cov(Y,Z)=\\5+7+10+2\times 2+2\times 0+2\times 2=30\]
and so
\[P(X+Y+Z<3)=\]
pnorm(3, 2, sqrt(30))
## [1] 0.5724339
x1=x[,1]+x[,2]+x[,3]
c(mean(x1), var(x1))
## [1] 1.99257 29.82532
sum(x1<3)/B
## [1] 0.57437
By theorem 2.3.16 \(X|Y=y\) has a normal distribution with mean
\[\rho=\frac{cov(X,Y)}{\sqrt{var(X)var(Y)}}=\frac{2}{\sqrt{5\times 7}}=0.338\]
\[\mu_1+\rho(\sigma_1/\sigma_2)(y-\mu_2)=1+0.338(\sqrt{5}/\sqrt{7})(1-0)=\\ 1+0.2857*1=1.2857\]
and variance
\[\sigma_1^2(1-\rho^2) = 5(1-0.338^2)=4.429\]
cor(x[,1:2])[1,2]
## [1] 0.3362009
pnorm(3, 1.2857, sqrt(4.429))
## [1] 0.7923437
x1=x[ abs(x[,2]-1)<0.1, 1]
c(length(x1),mean(x1), var(x1))
## [1] 2824.000000 1.262634 4.391849
sum(x1<3)/length(x1)
## [1] 0.8006374
\[ \begin{aligned} &P(X<Y) = P(X-Y<0)\\ &E[X-Y] = 1\\ &var(X-Y) =var(X)+var(-Y)+2cov(X,-Y)= \\ &var(X)+var(Y)-2cov(X,Y)=5+7-2\times2=8\\ &X-Y\sim N(1,\sqrt{8}) \end{aligned} \]
pnorm(0,1,sqrt(8))
## [1] 0.3618368
Here is a solution that would work more generally, also for distributions other than the normal:
\[ \begin{aligned} &P(X<Y) = \int_{-\infty}^{\infty} P(X<Y|Y=y)f_Y(y) dy = \\ &\int_{-\infty}^{\infty} P(X<y|Y=y)f_Y(y) dy = \\ = \\ &\int_{-\infty}^{\infty} F_{X|Y=y} (y|y)f_Y(y) dy = \\ &\int_{-\infty}^{\infty} pnorm(y,1+0.2857y,\sqrt{4.429})dnorm(y,0,\sqrt 7) dy \\ \end{aligned} \]
f = function(y)
pnorm(y,1+0.2857*y,sqrt(4.429))*dnorm(y,0,sqrt(7))
integrate(f,-Inf,Inf)
## 0.3618415 with absolute error < 9.8e-05
sum(x[,1]<x[,2])/B
## [1] 0.35992