# Measures in conditional expectation.

I always make confusion when a measure has to be changed in some other measure. This time I'm stuck on a change of measure in the definition of conditional expectation of a random variable.

If $Z$ is a r.v. with values in a countable set, we define the conditional law of $X$ given $Z$ as:

$n(z,A)=P(X\in A\ | \ Z = z)=\frac{P(X\in A\ , \ Z=z)}{P(Z=z)}$

Then we define the conditional expectation of $X$ given $Z=z$ as

$E(X \ | \ Z =z )=\int\limits_{\mathbb{R}} x \ n(z,dx)$

So I would like to change this formula $\int\limits_{\mathbb{R}} x \ n(z,dx)$ into this: $\frac{1}{P(Z=z)}\int\limits_{\{Z=z\}} X(\omega) \ P(d\omega)$

Intuitively is quite clear, but formally I don't get the right passage. My try:

$\int\limits_{\mathbb{R}} x \ n(z,dx) = \int\limits_{\mathbb{R}} x \ \frac{P(X\in dx\ , \ Z=z)}{P(Z=z)}=\frac{1}{P(Z=z)}\int\limits_{\mathbb{R}} x \ P(X\in dx, Z=z)$ and now?

How do I switch from the integration in $\mathbb{R}$ to the integration in $\Omega$ (the probability space)? Why I can pull out $Z=z$ from $P(X\in dx, Z=z)$ trasforming it into $\mathbb{1}_{\{Z=z\}}(\omega)$?

This follows from a standard argument which is often used in measure theory: To show that $$\int_{\mathbb{R}} f(x)\, n(z,\mathrm dx)=\frac{1}{P(Z=z)}\int_{\Omega} f(X)\mathbf{1}_{Z=z}\,\mathrm dP \tag{1}$$ holds for all measurable functions $f$, we first show that it holds for all indicator functions and then we extend to the more general case.
We see that $(1)$ holds for all $f=\mathbf{1}_A$ for some $A\in\mathcal{B}(\mathbb{R})$ since \begin{align} \int_{\mathbb{R}}\mathbf{1}_A(x)\, n(z,\mathrm dx)&=n(z,A)=\frac{1}{P(Z=z)}P(X\in A,Z=z)\\ &=\frac{1}{P(Z=z)}\int_\Omega \mathbf{1}_{A}(X)\mathbf{1}_{Z=z}\,\mathrm dP. \end{align} Now, note that if $(1)$ holds for two measurable functions $f$ and $g$, then $(1)$ also for $\alpha f+\beta g$ for all $\alpha,\beta\in\mathbb{R}$. That is, the functions satisfying $(1)$ constitutes a vector space. Lastly, if $(f_n)_{n\geq 1}$ is a non-decreasing sequence of measurable functions satisfying $(1)$ such that $\sup_n f_n(x)<\infty$ for all $x$, then also $\sup_n f_n$ satisfies $(1)$. The last is a consequence of the monotone convergence theorem.