change of random variable in calculating expectations: $\mathbb{E}_x [f(X)] = \mathbb{E}_z [f(g(Z))] $? Let $X$ be some function $g$ of a random variable $Z$, such that $X=g(Z)$.
Does the following hold in general? If so, how should I give a formal proof?
$$\mathbb{E}_x [f(X)] = \mathbb{E}_z [f(g(Z))] $$
For example, in showing the linearity of expectation, it's common to let $X=aZ+b$, then write $\mathbb{E}_x[X]=\mathbb{E}_z[aZ+b] = \int_{dz}(az+b) f(z) = a \mathbb{E}_z[Z] + b $, where I've always treated expectation $\mathbb{E}$ as an operator that averages w.r.t. the distribution of whatever random quantity in the argument.
 A: I believe I've finally learned enough measure theoretic probability to answer this question :)
It really just comes down to the formal definition of the expectation of a random variable, and the transformation ("change of measure") theorem.
The transformation theorem (see e.g., Schilling text theorem 15.1) basically says that given an "original" measure space $(\Omega, \mathcal{A}, \mu)$ and a measurable map $T: \Omega \to \Gamma$,  integrating a measurable function $u: \Gamma \to \bar{\mathbb{R}}$ w.r.t. the image measure $T(\mu) = \mu \circ T^{-1}$ is the same as integrating the composite function $u \circ T$ w.r.t. the "original" measure $\mu$,
i.e.,
$$\int_{\Gamma} u \text{ d} T(\mu) = \int_\mathcal{\Omega} u \circ T \text{ d} \mu(z) $$
So to justify the identity "$\mathbb{E}_x[X]=\mathbb{E}_z[aZ+b]$ if $X = g(Z) = aZ + b$" that I previously asked about, we just need to apply the above theorem to change the measure with respect to which we integrate from the probability law $\mathbb{P}$ of the underlying sample space $\Omega$, to the distribution $\mathbb{P}_Z:=Z(\mathbb{P})$ of $Z$, and finally to the distribution $\mathbb{P}_X:= g(Z(\mathbb{P})) = g(\mathbb{P}_Z)$ of $X:=g \circ Z$:
$$\mathbb{E}[X]=\mathbb{E}[g \circ Z]:= \int_\mathcal{\Omega} g \circ Z \text{ d} \mathbb{P} = \int g \text{ d} \mathbb{P}_Z =  \int x \text{ d} \mathbb{P}_X(x) $$
(the $u$ function in the last change of measure step is just the identity function, $u(x) = x$, and we consider $g: z \to x$ to be a random variable with $ \mathbb{E}[g]: = \int g \text{ d} \mathbb{P}_Z$).
In my example, $g(z) = az + b$, and suppose $\mathbb{P}_Z$ has density $f_Z$, $\mathbb{P}_X$ has density $f_X$, then
$$\mathbb{E}[X] := \int g \circ Z \text{ d} \mathbb{P} = \int (az + b )\text{ d} \mathbb{P}_Z (z) = \int (az + b) f_Z(z) \text{ d}z  = \int x f_X(x) \text{ d} x $$
as desired.
