Transformations of Random Variables

How a function changes a random variable's distribution, and why a density needs a scale correction.

Draft — not yet reviewed by the site owner.

Prerequisites: Random Variables.

A transformation of a random variable makes a new random quantity by applying a rule to an old one: if XX is a waiting time, Y=2XY=2X is that time in another unit. The challenge is to find the distribution of YY when we know the distribution of XX.

Start with an event, not a formula

The safest first step is to ask which values of XX produce Y≤yY\le y:

FY(y)=P(Y≤y)=P(g(X)≤y),Y=g(X).F_Y(y)=P(Y\le y)=P(g(X)\le y),\qquad Y=g(X).

This CDF method works even when gg folds several values of XX onto the same value of YY. It also forces us to identify the new support before writing a density.

For example, let XX be uniform on (−1,1)(-1,1) and let Y=X2Y=X^2. Then 0≤Y<10\le Y<1. For 0<y<10<y<1,

FY(y)=P(X2≤y)=P(−y≤X≤y)=2y2=y.\begin{aligned} F_Y(y)&=P(X^2\le y)\\ &=P(-\sqrt y\le X\le\sqrt y)\\ &=\frac{2\sqrt y}{2}=\sqrt y. \end{aligned}

Differentiating gives fY(y)=1/(2y)f_Y(y)=1/(2\sqrt y) for 0<y<10<y<1, and zero elsewhere. The density rises steeply near zero because a short interval near zero in YY collects values of XX from both sides of zero. The density becomes unbounded at zero, but its total area is still 1.

Left: y equals x squared maps both negative and positive x values to the same positive y. Right: the density of Y is highest near zero and falls as y approaches one.
Model, not data. X is uniform on (−1, 1) and Y = X². Both x = −√y and x = √y contribute to a positive y, giving f_Y(y) = 1/(2√y) for 0 < y < 1. The density is unbounded at zero but integrates to 1.

The one-to-one shortcut

Suppose gg is differentiable and strictly monotone on the support of a continuous XX. Write h=g−1h=g^{-1} for its inverse. Where hh is differentiable, the density of Y=g(X)Y=g(X) is

fY(y)=fX(h(y)) ∣h′(y)∣f_Y(y)=f_X(h(y))\,|h'(y)|

on the transformed support. The factor ∣h′(y)∣|h'(y)| corrects for stretching or squeezing: probability in a short interval must stay the same even when the interval’s width changes. For Y=2XY=2X, for example, h(y)=y/2h(y)=y/2 and ∣h′(y)∣=1/2|h'(y)|=1/2, so the density is half as tall over a range twice as wide.

The shortcut needs care when gg is not one-to-one. For g(x)=x2g(x)=x^2, the positive and negative branches both contribute. The CDF calculation above handles them automatically.

Several variables and the Jacobian

The same idea extends to two dimensions. When a one-to-one differentiable transformation maps (X,Y)(X,Y) to (U,V)(U,V), a small area may be stretched or squeezed. A Jacobian determinant measures that local change of area. The new joint density is the old density evaluated at the inverse map, multiplied by the absolute determinant of the inverse’s derivative matrix.

For instance, if U=X+YU=X+Y and V=YV=Y, then X=U−VX=U-V and Y=VY=V. The inverse changes area by a factor of 1, so

fU,V(u,v)=fX,Y(u−v,v)f_{U,V}(u,v)=f_{X,Y}(u-v,v)

on the transformed support. If instead U=2XU=2X and V=YV=Y, the inverse changes area by 1/21/2, and the density gains that factor. The formula is useful only after checking which (u,v)(u,v) values are possible.

Common misunderstandings

A density need not stay below 1. Its area must be 1; the height changes when the coordinate scale changes.

The inverse formula is a shortcut, not the starting point. With a many-to-one transformation, split into branches or use the CDF method. Always state the support and say the density is zero elsewhere.

Further reading