← Statistical Inference

Transforming random variables: the CDF method, the Jacobian, and the Cauchy distribution

How to find the density of a function of random variables with the CDF method and the change-of-variables formula, worked through for 1/X and X/Y, which both turn out to be Cauchy.

First explored September 2020·5 min read

University lab From my coursework in the MSc in Statistics and Machine Learning at Linköping University, rewritten as a note to review later.

probabilitychange-of-variablescauchy-distributionjoint-distributions

A lot of probability comes down to one question: if I know the distribution of XX (or of XX and YY together), what’s the distribution of some function of them? The first seminar of the probability theory course was full of these, and my handwritten solutions from that week show both standard methods, plus a couple of small slips worth fixing. Two results stand out because they’re surprising: if XX is Cauchy, so is 1/X1/X; and the ratio of two independent standard normals is Cauchy too.

Warm-up: marginals and independence from a joint density

If a joint density factorises as fX,Y(x,y)=g(x) h(y)f_{X,Y}(x,y) = g(x)\,h(y) over a rectangular region, then XX and YY are independent and each marginal is just the normalised factor. The marginal is obtained by integrating the other variable out:

fX(x)=∫fX,Y(x,y) dy,f_X(x) = \int f_{X,Y}(x, y)\, dy,

where the integral runs over all yy values where the density is positive.

For example, a density proportional to e−x2/2 e−3ye^{-x^2/2}\, e^{-3y} on −∞<x<∞-\infty < x < \infty, y>0y > 0 splits into a normal part and an exponential part. Integrating out yy leaves something proportional to e−x2/2e^{-x^2/2}, so X∼N(0,1)X \sim N(0, 1); integrating out xx leaves something proportional to e−3ye^{-3y}, so YY is exponential with rate 3 and density 3e−3y3e^{-3y}. The trick is to recognise the kernel (the part that depends on the variable) and let the normalising constant take care of itself. Independence then makes expectations of products easy: E[g(X) k(Y)]=E[g(X)] E[k(Y)]E[g(X)\,k(Y)] = E[g(X)]\,E[k(Y)], and second moments come from E[Y2]=Var(Y)+(EY)2E[Y^2] = \text{Var}(Y) + (E Y)^2.

Method 1: through the CDF

To get the density of Y=g(X)Y = g(X), write the CDF of YY as a probability about XX, then differentiate:

FY(y)=P(g(X)≤y),fY(y)=ddyFY(y).F_Y(y) = P(g(X) \le y), \qquad f_Y(y) = \frac{d}{dy} F_Y(y).

The care is all in turning "g(X)≤yg(X) \le y" into a set of xx values correctly.

Method 2: change of variables

If gg is strictly monotone and differentiable with inverse h=g−1h = g^{-1}, then

fY(y)=fX(h(y)) ∣dh(y)dy∣,f_Y(y) = f_X\big(h(y)\big)\, \left|\frac{dh(y)}{dy}\right|,

where the absolute value of the derivative (the Jacobian, in one dimension) accounts for how gg stretches or squeezes intervals. If gg is monotone on separate pieces, you add one such term per piece.

Example: 1/X1/X for a Cauchy XX

The standard Cauchy density is fX(x)=1π(1+x2)f_X(x) = \dfrac{1}{\pi(1+x^2)} for all real xx. Let Y=1/XY = 1/X. Here h(y)=1/yh(y) = 1/y and ∣h′(y)∣=1/y2|h'(y)| = 1/y^2. The map x↦1/xx \mapsto 1/x is decreasing on x<0x<0 and on x>0x>0 separately, and each y≠0y \neq 0 comes from exactly one xx, so

fY(y)=1π(1+1/y2)⋅1y2=1π(y2+1).f_Y(y) = \frac{1}{\pi\big(1 + 1/y^2\big)} \cdot \frac{1}{y^2} = \frac{1}{\pi(y^2 + 1)}.

So YY is standard Cauchy again.

My handwritten version had two slips on the way to the right answer. First, I wrote FY(y)=P(1/X≤y)=P(X≥1/y)F_Y(y) = P(1/X \le y) = P(X \ge 1/y). That’s only true when XX and yy are both positive. For y>0y > 0, 1/X≤y1/X \le y also holds for every negative XX, so the correct statement is P(1/X≤y)=P(X<0)+P(X≥1/y)P(1/X \le y) = P(X < 0) + P(X \ge 1/y). The derivative is the same, which is why the final answer still came out right, but the step itself was wrong. Second, I wrote fX(1−1/y)f_X(1 - 1/y) where it should have been fX(1/y)f_X(1/y), which was just a copying slip. The change-of-variables route above avoids the first trap altogether, since it never needs the sign cases.

Example: the ratio of two standard normals

Let X,YX, Y be independent N(0,1)N(0,1) and U=X/YU = X/Y. Use the CDF method:

P(U≤u)=P ⁣(XY≤u).P(U \le u) = P\!\left(\frac{X}{Y} \le u\right).

Multiplying through by YY flips the inequality when Y<0Y < 0:

P(U≤u)=P(X≤uY,  Y>0)+P(X≥uY,  Y<0).P(U \le u) = P(X \le uY,\; Y > 0) + P(X \ge uY,\; Y < 0).

Since XX is symmetric around 0 and independent of YY, P(X≥uY∣Y=y)=P(X≤−uy∣Y=y)P(X \ge uY \mid Y = y) = P(X \le -uy \mid Y=y), and for y<0y < 0, −uy=u∣y∣-uy = u|y|. So both pieces combine to

P(U≤u)=P(X≤u∣Y∣)=∫−∞∞Φ(u∣y∣) φ(y) dy,P(U \le u) = P\big(X \le u|Y|\big) = \int_{-\infty}^{\infty} \Phi(u|y|)\, \varphi(y)\, dy,

where φ\varphi and Φ\Phi are the standard normal density and CDF. In my notes I wrote P(X/Y≤v)=P(X≤v∣Y∣)P(X/Y \le v) = P(X \le v|Y|) directly. That’s the right result, but it needs the symmetry argument above; for a non-symmetric XX it would be false.

My notes stopped at the double integral. To finish, differentiate under the integral with respect to uu:

fU(u)=∫−∞∞∣y∣ φ(u∣y∣) φ(y) dy=2∫0∞y2πe−(1+u2)y2/2 dy=1π(1+u2).f_U(u) = \int_{-\infty}^{\infty} |y|\, \varphi(u|y|)\, \varphi(y)\, dy = 2\int_0^\infty \frac{y}{2\pi} e^{-(1+u^2)y^2/2}\, dy = \frac{1}{\pi(1+u^2)}.

The last integral is ∫0∞y e−ay2/2dy=1/a\int_0^\infty y\,e^{-a y^2/2}dy = 1/a with a=1+u2a = 1 + u^2. So X/YX/Y is standard Cauchy.

Why the Cauchy is a troublemaker

The Cauchy has such heavy tails that E∣X∣=∞E|X| = \infty: it has no mean and no variance. The law of large numbers doesn’t apply, and the average of nn Cauchy draws is itself standard Cauchy for every nn, so it never settles down. A quick simulation shows both results above and this behaviour:

set.seed(9)
n <- 1e5
x <- rcauchy(n)
ratio <- rnorm(n) / rnorm(n)
p <- c(0.1, 0.25, 0.5, 0.75, 0.9)
round(rbind(cauchy = qcauchy(p),             # -3.08 -1.00 0.00 1.00 3.08
            inv_x  = quantile(1 / x, p),     # about the same
            ratio  = quantile(ratio, p)), 2) # about the same
# Running means of Cauchy draws do not converge
round(sapply(c(1e2, 1e3, 1e4, 1e5), function(m) mean(x[1:m])), 2)

This is also a practical warning: ratios of noisy quantities whose denominators can be near zero can behave like Cauchy variables, with occasional huge values and unstable averages.

Key takeaways

  • A joint density that factorises over a rectangle means independence; marginals come from integrating the other variable out.
  • CDF method: write P(g(X)≤y)P(g(X) \le y) as a probability about XX, carefully, including sign cases, then differentiate.
  • Change of variables: fY(y)=fX(h(y)) ∣h′(y)∣f_Y(y) = f_X(h(y))\,|h'(y)|, summed over monotone pieces.
  • 1/X1/X for Cauchy XX, and X/YX/Y for independent standard normals, are both standard Cauchy.
  • The Cauchy has no mean; sample averages of Cauchy data don’t converge.

Resources

  • 732A63 Probability Theory, Linköping University, seminar exercises (autumn 2020).
  • Allan Gut, An Intermediate Course in Probability, 2nd ed., Springer, 2009, Chapter 1 (multivariate random variables and transformations).
  • George Casella and Roger L. Berger, Statistical Inference, 2nd ed., Duxbury, 2002, Section 2.1 (distributions of functions of a random variable) and Section 4.3 (bivariate transformations).