library(MASS)
# Run the function
rho <- 0.9
Sigma <- matrix(c(1, rho, rho, 1), 2, 2)
mu <- c(1, 2)
X <- mvrnorm(n = 10000, mu = mu, Sigma = Sigma)
plot(X)
abline(v = mu[1], h = mu[2], lty = 'dotted')
# consider the points such that x1-h <= X1 <= x1+h
x1 <- 1.3
h <- 0.1
indices <- which(abs(X[,1] - x1) < h) # the indices of X that fulfill the condition
X2 <- X[indices, 2]
points(X[indices, 1], X[indices, 2], col="blue")
abline(v = c(x1-h, x1+h))
# study the distribution of X2
# Is it a normal one ?
# What can you say of its mean ? Its variance ?
hist(X2, breaks = 30)
qqnorm(X2); qqline(X2)