How do I calculate this conditional expectation? I have $f(x)=x/8$ for $0<x<4$. I'm asked (in a practice test) to find $E[x\mid x \ge 2]$.
My solution, based on something our TA showed us but I didn't fully understand, is as follows:
I took the integral $\int_0^2 x(x/8)\,dx$ divided by the integral $\int_0^2 x/8\,dx$. I got $4/3$.
Is this correct? If so, can someone explain the intuition behind this method?
 A: In general, if you have a probability distribution $p(x)$, the expected value of $x$ is $$\int_{-\infty}^{\infty}xp(x)dx$$
By definition, a probability distribution must integrate to $1$, i.e. $\int_{-\infty}^{\infty}p(x)=1$.  In your case, the distribution you are given is 
$$f(x)=\begin{cases}x/8 & 0<x<4\\0 &\text{otherwise} \end{cases}$$
Indeed, this function integrates to $1$.  However, you are now asked to condition on the fact $x>2$.  What is the distribution of $x$ given that we now know it is greater than $2$?  Well, the distribution should look the same as before, except now it should be $0$ when $x\leq 2$.  This gives us a modified distribution:
$$g(x)=\begin{cases}x/8 & 2<x<4\\0 &\text{otherwise} \end{cases}$$
But wait! Now this doesn't integrate to $1$.  It integrates to $\int_{-\infty}^{\infty}g(x)=\int_{2}^4x/4=\frac{x^2}{16}|_{x=2}^4=\frac{3}{4}$.  Consider the function
$$h(x)=\frac{g(x)}{\int_{-\infty}^{\infty}g(x)}=\frac{g(x)}{3/4}$$
$h(x)$ is distributed like $g(x)$, but integrates to $1$, as needed to be a proper probability distribution.  Thus the expectation you're after is
$$\int xh(x)dx$$
A: The formulation of that rule in more general form is: $$\mathbb E[X\mid X\in B]=\frac{\mathbb EX\mathbf1_{X\in B}}{P(X\in B)}\tag1$$ where $B$ denotes a Borel set and $P(X\in B)>0$. 

I choose for an example to make things more clear
Let   $X$ be a discrete random variable that takes values in $\{-3,1,2\}$ with $P(X=-3)=\frac13$, $P(X=1)=\frac12$ and $P(X=2)=\frac16$.
What happens if we must focus on $X$ under condition $X\in\{1,2\}$?
The ratio of the probabilities on $1$ and $2$ must stay as it was, but both must be muliplied by factor $\frac1{P(X\in\{1,2\})}$ to achieve that: $$P(X=1\mid X\in\{1,2\})+P(X=2\mid X\in\{1,2\})=1$$
This results in $P(X=1\mid X\in\{1,2\})=\frac34$ and $P(X=2\mid X\in\{1,2\})=\frac14$.
This explains the denominator in $(1)$
The numerator is explained by the fact that for finding the corresponding expectation we are only interested in the values $1,2$ and not anymore in value $-3$. 
