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

$\displaystyle 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

$\displaystyle \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

$\displaystyle 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:

$\displaystyle \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