# General way to calculate or think about non-linear but monotonic (?) transforms of random variables

I am doing a lot of work with lognormal RVs.

I am trying to get my head around the formal mathematics of the non-linear transform of a random variable, particularly where there isn't any 'wraparound' (as there would be with $X^2$ if $X$ were normally distributed), but simply 'compression' or 'expansion' of the X axis.

The lognormal distribution is an excellent example of that. If $X$ is distributed as $N(\mu, \sigma)$, then $Y=e^X$ is lognormal.

Intuitively it is easy to get the basic idea: if one is thinking about the pdf, roughly speaking, equal-sized increments from the pdf of $X$ when $X>0$ get mapped over a bigger region in 'Y-space'; similarly, when $X<0$, things get compressed. Wikipedia has a great graphic on this idea: https://en.wikipedia.org/wiki/Log-normal_distribution#/media/File:Lognormal_Distribution.svg

I am working with both exact and numerical methods, and am looking for the general abstraction that covers this. For instance, given an (arbitrary) distribution in 'Y-space', I would like to map it backwards into 'X-space'. Intuitively, I would like to take the 'logarithm' of Y if, instead of being lognormal, Y were (say) a Student's t distribution.

I note that such transforms are not trivially obvious. For example, if one wants to go from a lognormal RV $Y$ with known mean and standard deviation, to map back to the normally distributed RV $X$ underlying it, the formulas are not obvious - also, as noted in Wikipedia, they are: I suspect I am in the area of the Radon-Nikodym derivative, but my knowledge of measure theory is too incomplete to be sure.

It sounds like you want the formula for the density transformation under a monotonic function. If you start with a continuous random variable $X$ and you define the random variable $Y=f(X)$ using a strictly monotonic transformation $f$, you can derive a simple transformation rule for the densities. To facilitate the analysis let $y=f(x)$ so that $x=f^{-1}(y)$. (The inverse function is guaranteed to exist since $f$ is strictly monotonic.) We examine increasing and decreasing transforms separately.

Case I (increasing transformation): If $f$ is increasing then:

$$F_Y(y) = \mathbb{P}(Y \leqslant y) = \mathbb{P}(f(X) \leqslant y)= \mathbb{P}(X \leqslant f^{-1}(y)) = F_X(x).$$

Differentiating to obtain the density of $Y$ gives:

$$f_Y(y) = \frac{dF_Y}{dy}(y) = \frac{d}{dy} F_X(x) = f_X(x) \frac{dx}{dy}.$$

Case II (decreasing transformation): If $f$ is decreasing then:

$$F_Y(y) = \mathbb{P}(Y \leqslant y) = \mathbb{P}(f(X) \leqslant y)= \mathbb{P}(X \geqslant f^{-1}(y)) = 1-F_X(x).$$

Differentiating to obtain the density of $Y$ gives:

$$f_Y(y) = \frac{dF_Y}{dy}(y) = \frac{d}{dy} (1-F_X(x)) = -f_X(x) \frac{dx}{dy}.$$

General transformation rule: These two transformation rules can be combined into a single general formula for density transformation for all strictly monotonic transformations:

$$f_Y(y) = f_X(x) \Bigg| \frac{dx}{dy} \Bigg|.$$

This is a well-known density transformation rule that can be found in most textbooks on elementary probability theory. As you can see, under a strictly monotonic transformation, the density of $Y$ is equal to the product of the density of $X$ (evaluated at the corresponding value) multiplied by the absolute value of the derivative of the inverse function $f^{-1}$ (it can also be expressed equivalently as division by the absolute value of the derivative of the original function $f$).

The general abstraction you are looking for is the concept of pushforward measure.

In a special setting, when the random variable $X$ is supported on the real line, the expected value of $Y = f(X)$ can be computed as $$\mathbb{E}[f(X)] = \int_{-\infty}^{\infty} f(u) p_X(u) du,$$ where $p_X(u)$ is the probability density function of $X$. So as you can see, the expectations does not transform as $\mathbb{E}[f(X)] = f(\mathbb{E}[X])$, although this holds for the linear case.