## From expectations to variance

Hi,

suppose that X, Y, and Z are random variables with joint distribution P(X, Y, Z). By

$E_Y[f(X, Y, Z) | z] = \sum_y P(y) f(X, y, Z| z).$

we denote the conditional expectation over the distribution of Y. Now I have an expression of the form

$\sum_{x, y, z} P(x, y, z) (E_Y[f(x, y, z) | z] - f(x, y, z))^2.$

How should I transform the last equation to include a variance term of the form

$V_Y[f(X, Y, Z) | z] = E_Y[f(X, Y, Z) - E_Y[f(X, Y, Z) | z] | z]$

where expectations are taken over the distribution Y?

I am stuck at the following equation:

$\sum_{x, y, z} P(x, z | y) P(y) (E_Y[f(x, y, z) | z] - f(x, y, z))^2.$

Thanks and best regards

samosa