# Expectation of Multidimensional Function of Random Variables w.r.t. Marginal Distribution

Suppose two random variables $X$ and $Y$ are given. $\mathbb{E}(XY)$ will be the uncentered covariance of them. But this expectation is with respect to the joint distribution $P(X,Y)$. My question is what is the expectation if we take the expectation w.r.t say $Y$, i.e. something like $$\mathbb{E}_Y(XY)= \int XY dP(Y)$$ I first thought $X$ will come out of the integral so that we would get: $$\mathbb{E}_Y(XY)= X\int Y dP(Y)$$ but I realized that doesn't make sense since if say $Y=X$ this would be a wrong equation. So now I think it actually equates the conditional expectation, meaning that: $$\mathbb{E}_Y(XY)= \int \mathbb{E}(X|Y=y)y dP(Y)$$ I am still not sure if this is correct. I would appreciate any help or clarification on a misunderstanding of mine.

P.S. Cross-posted in http://math.stachexchange.com

• I think you are after en.wikipedia.org/wiki/Law_of_total_expectation – Sid Feb 4 '18 at 21:04
• Thank you for your reply. I am very confused. What I am wondering is that either $\int f(X,Y)dP(y)$ is well-defined or not. And if not, why not? I guess I am having a conversation on math.stackexchange but thanks a lot. – Cupitor Feb 5 '18 at 16:21

If you condition on (fix) the value of $X$, then the expectation you are calculating is $\mathbb{E}(Y|X)=\int XY dP(Y|X)$ and you may safely move $X$ to the left hand side (outside the integral) because by conditioning, you are turning-at least temporarily-this random variable into a constant. If instead you want the joint expectation you need to integrate over both the measure on $X$ and the measure on $Y$. This may be done is 2 ways, directly evaluating both integrals or evaluating the conditional expectation and then take this result as a function of $X$ (or $Y$ if you conditioned on that one instead) and integrate over the density of the-previously fixed-variable. Both approaches should give you the same result so you can use that as a logical check that you made no errors.
Note: In the post, the measure when integrating is written as $dP(Y)$, when this should be $dP(Y|X)$. This is likely what is causing the confusion.
Why can't you use $dP(Y)$? As noted in the comments there are all manner of ways that the random variable $X$ could be a function of $Y$ and that would cause all sorts of strange things that would not be logically consistent to occur.