Tutorials › Stochastic Processes › Transforming Random Variables by Change of Variables

Random Variables, Expectation and Conditional Expectation · Tutorial 6 of 994

Transforming Random Variables by Change of Variables

Derive transformed distributions by tracking probability across the preimages of each value, with Jacobians handling continuous changes of variables.

Intermediate 12 min read

What You'll Learn

  • Compute the probability mass function of a discrete transformation by adding masses over each fiber.
  • Apply the derivative formula for a strictly monotone transformation of a continuous random variable.
  • Account for every inverse branch when a transformation is not one-to-one.
  • Use a Jacobian to transform a joint density and determine its new support.
  • Derive the joint law, sum distribution, and ratio distribution for independent exponential variables.
  • Check transformed laws by integrating or summing their total probability.

How a Transformation Changes a Distribution

A random variable can be transformed without changing the underlying experiment: a discrete variable might be squared, or two continuous variables might be replaced by their sum and ratio. The distribution of the new variable is determined by how the original probability is arranged over the values that map to it. For discrete variables, probabilities from all preimages are added. For continuous variables, the derivative or Jacobian adjusts for how the transformation stretches or compresses space.

Let \((\Omega,\mathcal{F},\mathbb{P})\) be a probability space. If \(X\) is a random variable and \(g\) is a measurable function, the transformed random variable is \(Y=g(X)\). Its distribution is defined by \(\mathbb{P}(Y\in B)=\mathbb{P}(X\in g^{-1}(B))\) for each measurable set \(B\). The challenge is to turn this definition into a mass function or density that can be used directly.

Discrete Transformations: Add the Masses in Each Fiber

Proposition (Discrete transformation): Suppose \(X\) takes values in a finite or countable set \(S\), with probability mass function \(p_X(x)=\mathbb{P}(X=x)\), and let \(Y=g(X)\). For every value \(y\) in the image of \(g\), $$ p_Y(y)=\mathbb{P}(Y=y)=\sum_{\{x\in S:g(x)=y\}}p_X(x). $$ The sum includes every \(x\) mapped to \(y\).

Proof. The event \(\{Y=y\}\) is exactly the union of the events \(\{X=x\}\) over all \(x\in S\) satisfying \(g(x)=y\). These events are pairwise disjoint, since \(X\) cannot equal two different values at once. Countable additivity therefore gives \(\mathbb{P}(Y=y)=\sum_{x:g(x)=y}\mathbb{P}(X=x)\). If \(y\) is not in the image of \(g\), its preimage is empty and the probability is zero. \(\square\)

Worked Example: Squaring a Discrete Random Variable

Suppose \(X\) takes values \(-2,-1,0,1,2\) with respective probabilities \(\tfrac{1}{10},\tfrac{1}{5},\tfrac{1}{5},\tfrac{3}{10},\tfrac{1}{5}\). Find the probability mass function of \(Y=X^2\).

First check the original probabilities: \(\tfrac{1}{10}+\tfrac{1}{5}+\tfrac{1}{5}+\tfrac{3}{10}+\tfrac{1}{5}=\tfrac{1+2+2+3+2}{10}=1\). The possible values of \(Y\) are \(0,1,4\). The preimages are \(\{0\}\) for \(0\), \(\{-1,1\}\) for \(1\), and \(\{-2,2\}\) for \(4\). Thus $$ \begin{aligned} \mathbb{P}(Y=0)&=\mathbb{P}(X=0)=\tfrac{1}{5},\\ \mathbb{P}(Y=1)&=\mathbb{P}(X=-1)+\mathbb{P}(X=1)=\tfrac{1}{5}+\tfrac{3}{10}=\tfrac{1}{2},\\ \mathbb{P}(Y=4)&=\mathbb{P}(X=-2)+\mathbb{P}(X=2)=\tfrac{1}{10}+\tfrac{1}{5}=\tfrac{3}{10}. \end{aligned} $$ Check: The transformed probabilities sum to \(\tfrac{1}{5}+\tfrac{1}{2}+\tfrac{3}{10}=\tfrac{2+5+3}{10}=1\). In particular, the probabilities at \(1\) and \(4\) combine two distinct original masses each.

One-Dimensional Continuous Transformations

For a continuous random variable, there is no positive probability at an individual point to add up. Instead, a density describes probability over small intervals. If \(g\) is strictly monotone and differentiable, nearby values of \(X\) are mapped to nearby values of \(Y=g(X)\). The absolute derivative of the inverse accounts for the change in interval length.

Theorem (Density under a monotone transformation): Suppose \(X\) has density \(f_X\) on an interval \(I\), and \(g:I\to J\) is strictly monotone, continuously differentiable, and has nonzero derivative on the interior of \(I\). For \(Y=g(X)\), let \(x=g^{-1}(y)\). For \(y\) in the interior of \(J=g(I)\), $$ f_Y(y)=f_X\!\left(g^{-1}(y)\right)\left|\frac{d}{dy}g^{-1}(y)\right| =\frac{f_X(x)}{|g'(x)|}. $$ Set the density to zero outside \(J\); endpoint values do not affect the distribution.

Proof. First suppose \(g\) is increasing. For an interior point \(y\), the distribution function satisfies \(F_Y(y)=\mathbb{P}(g(X)\le y)=F_X(g^{-1}(y))\). Differentiating by the chain rule gives \(f_Y(y)=f_X(g^{-1}(y))(g^{-1})'(y)\); the inverse derivative is positive and equals \(1/g'(g^{-1}(y))\). If \(g\) is decreasing, the event becomes \(\{X\ge g^{-1}(y)\}\), so \(F_Y(y)=1-F_X(g^{-1}(y))\). Differentiating gives \(f_Y(y)=f_X(g^{-1}(y))[-(g^{-1})'(y)]\). Here the inverse derivative is negative and has absolute value \(1/|g'(g^{-1}(y))|\). In either case the stated absolute-derivative formula follows. Outside \(J\), \(Y\) has no values, so its density is zero. \(\square\)

Worked Example: The Negative Logarithm of a Uniform Variable

Let \(X\) have the uniform density \(f_X(x)=1\) for \(0<x<1\), and zero elsewhere. Find the density of \(Y=-\ln X\).

The map \(g(x)=-\ln x\) is strictly decreasing on \((0,1)\), and its image is \((0,\infty)\). Its inverse is \(x=e^{-y}\), with derivative \(-e^{-y}\). The transformation formula gives $$ f_Y(y)= \begin{cases} e^{-y},&y>0,\\ 0,&y\le 0. \end{cases} $$ Check by integration: \(\int_0^\infty e^{-y}\,dy=[-e^{-y}]_0^\infty=0-(-1)=1\). One can also check the distribution function directly: for \(y\ge0\), \(Y\le y\) means \(X\ge e^{-y}\), so \(\mathbb{P}(Y\le y)=1-e^{-y}\). Differentiating this expression gives \(e^{-y}\) for \(y>0\), as above; for \(y<0\), the probability is zero.

When There Is More Than One Inverse

Strict monotonicity matters: without it, one output value can come from several input values. When a differentiable transformation has finitely many inverse branches and nonzero derivative at the preimages, each branch contributes a density term. In one dimension, at a regular value \(y\), the formula is $$ f_Y(y)=\sum_{\{x:g(x)=y\}}\frac{f_X(x)}{|g'(x)|}. $$ This is the same local stretching adjustment as before, summed over all the ways to produce \(y\). The formula applies on regions where the preimages are regular; isolated endpoints or critical values require separate attention but do not affect a density if they have probability zero.

Worked Example: Squaring a Continuous Random Variable

Let \(X\) be uniform on \((-1,1)\), so \(f_X(x)=\tfrac{1}{2}\) there, and let \(Y=X^2\). Find the density of \(Y\).

The range is \(0\le Y<1\). For \(0<y<1\), the two preimages are \(x=\sqrt{y}\) and \(x=-\sqrt{y}\). Since \(g'(x)=2x\), each branch contributes \(\tfrac{1}{2}/(2\sqrt{y})=\tfrac{1}{4\sqrt{y}}\). Adding both contributions gives $$ f_Y(y)= \begin{cases} \dfrac{1}{2\sqrt{y}},&0<y<1,\\ 0,&\text{otherwise}. \end{cases} $$ Check by integration: \(\int_0^1 \tfrac{1}{2\sqrt{y}}\,dy=[\sqrt{y}]_0^1=1\). A distribution-function check gives, for \(0\le y\le1\), \(\mathbb{P}(Y\le y)=\mathbb{P}(-\sqrt y\le X\le\sqrt y)=\tfrac{2\sqrt y}{2}=\sqrt y\); its derivative on \((0,1)\) is the same density. The endpoints have probability zero because \(X\) has a density.

Joint Transformations: The Jacobian

For two variables, a transformation can change both coordinates at once. The corresponding adjustment is the absolute determinant of the derivative matrix of the inverse transformation. It measures how areas in the transformed coordinates correspond to areas in the original coordinates.

Theorem (Change of variables for a joint density): Let \((X_1,X_2)\) have joint density \(f_X(x_1,x_2)\) on a region \(D\). Suppose \(T:D\to E\) is one-to-one, continuously differentiable, and has a continuously differentiable inverse \(G:E\to D\), with \(\det DG(y)\ne0\) in the interior of \(E\). For \((Y_1,Y_2)=T(X_1,X_2)\), the joint density on \(E\) is $$ f_Y(y_1,y_2)=f_X(G(y_1,y_2))\left|\det DG(y_1,y_2)\right|, $$ and it is zero outside \(E\).

Proof. For a measurable region \(A\subseteq E\), the definition of a joint density gives \(\mathbb{P}((Y_1,Y_2)\in A)=\int_{T^{-1}(A)} f_X(x_1,x_2)\,dx_1dx_2\). Apply the multivariable change-of-variables formula from calculus to the one-to-one map \(x=G(y)\). The integral becomes \(\int_A f_X(G(y_1,y_2))|\det DG(y_1,y_2)|\,dy_1dy_2\). Since this identity holds for every measurable \(A\), the integrand on \(E\) is a joint density for \((Y_1,Y_2)\). Outside \(E\), the transformed pair cannot take values, so the density is zero. \(\square\)

Worked Example: The Sum and Ratio of Two Exponential Variables

Let \(X\) and \(Y\) be independent, each with density \(e^{-x}\) for \(x>0\) and zero otherwise. Define the sum \(U=X+Y\) and the ratio \(V=X/(X+Y)\). Find their joint density and the marginal densities. Independence gives the joint density \(f_{X,Y}(x,y)=e^{-x-y}\) for \(x>0,y>0\), and zero elsewhere.

The transformed region is \(u>0,\ 0<v<1\). Solving \(u=x+y\) and \(v=x/(x+y)\) gives \(x=uv\), \(y=u(1-v)\). The inverse derivative matrix and its determinant are $$ DG(u,v)= \begin{bmatrix} v&u\\ 1-v&-u \end{bmatrix}, \qquad \det DG(u,v)=-uv-u(1-v)=-u. $$ Thus the absolute Jacobian is \(u\), and \(x+y=uv+u(1-v)=u\). The joint density is $$ f_{U,V}(u,v)= \begin{cases} u e^{-u},&u>0,\ 0<v<1,\\ 0,&\text{otherwise}. \end{cases} $$

To obtain the density of \(U\), integrate over \(v\): for \(u>0\), \(f_U(u)=\int_0^1 ue^{-u}\,dv=ue^{-u}\), and it is zero otherwise. To obtain the density of \(V\), integrate over \(u\): for \(0<v<1\), $$ f_V(v)=\int_0^\infty ue^{-u}\,du=1. $$ The integral equals \(1\) because integration by parts gives \(\int_0^\infty ue^{-u}\,du=[-ue^{-u}]_0^\infty+\int_0^\infty e^{-u}\,du=0+1\). Hence \(V\) is uniform on \((0,1)\). Check: the joint density has total integral \(\int_0^1\int_0^\infty ue^{-u}\,du\,dv=1\cdot1=1\); also, \(\int_0^\infty ue^{-u}\,du=1\) verifies the marginal density of \(U\) integrates to one, and \(\int_0^1 1\,dv=1\) verifies the marginal density of \(V\).

A Common Pitfall: Losing a Preimage

A transformation formula must account for every inverse branch. For the continuous square example, using only \(x=\sqrt{y}\) would give the incorrect density \(\tfrac{1}{4\sqrt{y}}\) on \(0<y<1\). Its total integral is \(\int_0^1\tfrac{1}{4\sqrt{y}}\,dy=\tfrac{1}{2}\), not \(1\). The missing half is the contribution from \(x=-\sqrt{y}\). The corrected density adds both branches and integrates to one. In a discrete transformation the same mistake appears as omitting one input value from the fiber.

Support is another essential part of the calculation. A formula obtained from a derivative or Jacobian only applies where the transformed value is attainable. For example, the sum and ratio transformation above has \(u>0\) and \(0<v<1\), not every point in the plane. Values outside this region must have density zero. Finally, a continuous density is determined up to changes on sets of area or length zero, so choices at boundary points do not change the distribution.

Check Your Understanding

For each question, identify the support as well as the mass function or density, and check that the total probability is one.

  1. If \(X\) takes values \(-1,0,1\) with probabilities \(\tfrac14,\tfrac12,\tfrac14\), find the mass function of \(X^2\). Which original values contribute to the mass at \(1\)?
  2. If \(X\) is uniform on \((0,2)\), find the density of \(Y=3X+1\) using the monotone transformation formula.
  3. If \(X\) is uniform on \((-2,2)\), find the density of \(Y=X^2\) by accounting for both inverse branches.
  4. For independent exponential variables with rate \(1\), use the transformation \(U=X+Y,\ V=X/(X+Y)\) to state the inverse map and absolute Jacobian.
  5. Why does a proposed density obtained from a change of variables need to be checked on its transformed support?