Let \((X, Y)\) be the (random) coordinates of a point uniformly drawn from the unit square. In other words, both \(X,Y\) are uniform random variables on the interval \((0, 1)\), and they are both independent of each other. Let’s sample some of these points and plot them:
n <- 100
xcoords <- runif(n)
ycoords <- runif(n)
# Visualize----
plot(xcoords, ycoords, pch = 19,
asp = 1) # Fix aspect ratio
Because of the independence between \(X,Y\), the conditional expected value of \(X\) given \(Y\) is equal to the (unconditional) expected value of \(X\):
\[ E(X \mid Y) = E(X) = 0.5.\]
But what about the conditional expectation \(E(X \mid X + Y > 1)\)? We can try to estimate this quantity through Monte Carlo integration. The first observation is that the condition \(X + Y > 1\) means we should restrict our sample to the samples for which the condition is true (remember conditional probabilities: we need to restrict the sample space). Let’s visualize these points:
colour <- ifelse(xcoords + ycoords > 1,
"red", "black")
# Visualize----
plot(xcoords, ycoords, pch = 19,
asp = 1, col = colour)
segments(0, 1, 1, 0) # Boundary
Therefore, we can estimate \(E(X \mid X + Y > 1)\) by taking the sample mean of the red points only.
keep <- xcoords + ycoords > 1
mean(xcoords[keep]) # Compare to 0.5
## [1] 0.6598403
This estimate is larger than the unconditional expected value \(E(X)\). This makes sense: on the graph, we can clearly see that there are more red points with larger values of the x-coordinate than smaller values.