## Random Variables: Calculating E[X|Y]

1. The problem statement, all variables and given/known data
This is an example in a textbook; it already has the solution. I don't understand how E[X|Y] was obtained though. So my question is how do I calculate E[X|Y] from the information given?

This last part is probably not needed to solve the problem, I think. But I am adding it for completeness and context.

E[X] is the expected value, or mean, of X.

2. Relevant equations

$$E[X|Y] = \int_{-\infty}^{\infty} x f_{X|Y}(x|y)dx$$

Law of Total Variance: var(X) = E[var(X|Y)] + var(E[X|Y])

3. The attempt at a solution

I don't really understand how X is dependent on Y. It seems to me that Y is dependent on X! I'm really lost with this material, though. I don't have fX|Y(x|y) and I think that E[X|Y] is independent of Y, which would imply that E[X|Y] = E[X].
$$E[X] = 1/2\int_{0}^{1} x dx + 1/4\int_{1}^{3} x dx = 1/2*1 + 1/4*2 = 1?$$
E[X|Y] is supposed to be a random variable that is a function of Y though. I just don't see how Y plays any part in the computation.
 Just forget about the integrals and junk and just think about what that is telling you to do. E[X|Y=y] says what is the expected value of the variable X given we know Y is a certain value. So, Y can take on 2 values -- 1 and 2. Let's write these out: E[X|Y = 1] and E[X|Y = 2] So what do we know about X if we know Y = 1? We know, by the definition of Y, that X < 1. So the conditional pdf of X is the region between 0 and 1 normalized such that the area from 0 to 1 equals 1.Like this: $$f_{X|Y=1}(x) = \frac{f_X(x)}{p[Y=1]}$$ where f_x(x) is only nonzero where y = 1 (meaning x < 1) $$f_{X|Y=1}(x) = \frac{f_X(x)}{\int\limits_{0}^{1} f_X(x)dx}=\frac{f_X(x)}{\frac{1}{2}}=2f_X(x)$$ Once we have this conditional pdf, just plug it into the integral definition of expectation $$\int\limits_{0}^{1} 2xf_X(x) dx$$ Note, again, the limits here are because this f_X(x) (it is bad notation, I know) is actually nonzero only where x < 1 since it comes from finding the P[X <= x AND Y = y] in the equation $$P[X \le x | Y = y] = \frac{P[X \le x \cap Y = y]}{P[Y=y]}$$ For the other one, it's the exact same except we know x is greater than or equal to 1.
 Thanks for answering. Can we always assume the if is biconditional (if and only if)? It seems that you interpret IF x <1, then Y=1 to also mean, IF Y =1, then x <1. I'm also not sure why $$f_{X|Y=1}(x) = 2*f_X(x) = 1$$ I think this is the probability for E[X|Y=1], isn't it supposed to be 1/2? I assumed that f_X(x) = 1/2, since that's its value between 0 and 1.

## Random Variables: Calculating E[X|Y]

 Quote by Joshuarr Thanks for answering. Can we always assume the if is biconditional (if and only if)? It seems that you interpret IF x <1, then Y=1 to also mean, IF Y =1, then x <1. I'm also not sure why $$f_{X|Y=1}(x) = 2*f_X(x) = 1$$ I think this is the probability for E[X|Y=1], isn't it supposed to be 1/2? I assumed that f_X(x) = 1/2, since that's its value between 0 and 1.
There is no interpretation. If someone tells you the only way you can make Y = 1 is for X < 1 and they also tell you Y = 1, you know X < 1.

I derived for you the conditional pdf. The conditional expectation is found through weighted integration of the conditional pdf:
$$E\{X|Y=1\}=\int\limits_{0}^{1} 2xf_X(x) dx =\int\limits_{0}^{1} 2x\frac{1}{2} dx=\int\limits_{0}^{1} x dx=\frac{1}{2}$$

But of course, you can just use the common sense notion of expectation to figure it out. The first one is uniform from 0 to 1, so its average value is 1/2. The second is uniform from 1 to 3, so its average value is 2.
 I really appreciate your clarification. The problem that I was having was rationalizing how the probability of E[X|Y=1] and E[X|Y=2] is 1/2, but I think I understand now. Thank you!

 Tags conditional, probability, random variables