# Probability density function after transformation

Let $$X,Z$$ be random variables with probability density functions $$p_X,p_Z$$. Suppose $$Z=f(X)$$, where $$f$$ is continuous and differentiable. How is $$p_Z$$ related to $$p_X$$? It's tempting to say $$p_Z(z) = p_X(f^{-1}(z))$$, but I think that is not correct: I think it might be

$$p_Z(z) = {p_X(f^{-1}(z)) \over f'(f^{-1}(z))},$$

where $$f'$$ is the derivative of $$f$$, but I am not sure whether I've got that right. What is the correct rule?

The correct rule is

$$p_Z(z) = \sum_{x \in f^{-1}(z)} {p_X(x) \over f'(x)},$$

as there can be multiple possible values $$x$$ that satisfy $$f(x)=z$$.

One way to derive this, in the case of a monotonic $$f$$ (so there is only a single $$x$$ such that $$f(x)=z$$), is to consider the cdfs $$f_X,f_Z$$. Then we have

$$F_Z(z) = \Pr[Z \le z] = \Pr[f(X) \le z] = \Pr[X \le f^{-1}(x)] = F_X(f^{-1}(z))$$

and

\begin{align*} p_Z(z) &= {d \over dz} F_Z(z) = {d \over dz} (F_X(f^{-1}(z)))\\ &= ({d \over dz} F_X)(f^{-1}(z)) \cdot {d \over dz} f^{-1}(z)\\ &= p_X(f^{-1}(z)) \cdot 1/f'(f^{-1}(z)). \end{align*}