Covariance/Joint Expectation Calculation

51 Views Asked by At

$f_{X,Y}(x, y) = 6xI_{0 < x < y < 1}$

Question asks for the covariance, which is of course E[XY] - E[X]E[Y].

So to get E[XY], I set it up as:

$\int_0^1 \int_0^y xy6x \text{ } dx dy$

Which results in $\frac{2}{5}$.

But when I simulate it in R, I get 2 as the expectation of the joint. So I guess the issue is whether my R sim is wrong, or the setup here is wrong. FWIW, this was my R code -- not necessarily looking for comment on this as opposed to my setup above, as determining that the setup above is correct or incorrect is really what I am interested in, but I figure someone will inevitably ask for it. :-) :

vect <- rep(NA, 1e4)

for(i in 1:1e4){

x <- 2

y <- 1

while(x > y){       
    x <- runif(1, 0, 1)
    y <- runif(1, 0, 1)
}

tx <- 6*x

vect[i] <- tx

}

mean(vect)