F4 · Random Variables and Expectation · Lesson 6 of 8
Transformations of Random Variables
Find the distribution of a function of random variables: the CDF method, the change-of-variables formula, convolution for sums, minima and maxima, and the lognormal.
18 min
The question
You know the distribution of X (or of X and Y) and want the distribution of Y=g(X), of X+Y, or of max(X,Y). Interviewers ask this directly ("what is the density of U2?") and indirectly, whenever a payoff, a price or a waiting time is a function of something simpler.
The intuition: probability mass is moved, not created. A transformation carries each small piece of probability to a new location. Where the map stretches an interval, the same mass is spread thinner and the density falls; where it compresses, the density rises.
The CDF method always works
Go through the CDF, never straight to the density:
FY(y)=P(g(X)≤y)=P(X∈{x:g(x)≤y}),
then differentiate. The only real work is describing the set {x:g(x)≤y} correctly.
Example.U∼Uniform(0,1) and Y=U2. For 0≤y≤1, P(U2≤y)=P(U≤y)=y, so fY(y)=2y1. The density blows up near 0 because squaring crushes [0,0.1] into [0,0.01].
Non-monotone example.Z∼N(0,1) and Y=Z2. For y>0, P(Z2≤y)=P(−y≤Z≤y)=2Φ(y)−1. Differentiating,
fY(y)=2y2φ(y)=2πy1e−y/2,y>0,
the chi-squared distribution with one degree of freedom. Both branches ±y contribute.
The change-of-variables formula
If g is strictly monotone and differentiable with inverse h=g−1, differentiating the CDF gives
fY(y)=fX(h(y))∣h′(y)∣.
The factor ∣h′(y)∣ is the stretching correction: it converts "mass per unit of x" into "mass per unit of y". For a map that is monotone on pieces, sum this expression over every x with g(x)=y, as in the Z2 example.
Two consequences worth knowing:
Quantiles commute with increasing maps; means do not. The median of g(X) is g(median of X), but E[g(X)]=g(E[X]) unless g is linear. Jensen's inequality says which way: E[g(X)]≥g(E[X]) for convex g.
Probability integral transform. If X is continuous with CDF F, then F(X)∼Uniform(0,1), because P(F(X)≤u)=P(X≤F−1(u))=u. Run backwards, F−1(U) has CDF F: this is inverse-transform sampling.
The lognormal, from the normal
If X∼N(μ,σ2) and Y=eX, then h(y)=lny and h′(y)=1/y, so
fY(y)=yσ2π1exp(−2σ2(lny−μ)2),y>0.
Its moments come from the normal moment generating function E[etX]=eμt+σ2t2/2 with t=1 and t=2:
Quantity
Value
Mean
eμ+σ2/2
Variance
(eσ2−1)e2μ+σ2
Median
eμ (quantiles commute with exp)
Mode
eμ−σ2
So for any σ>0, mode < median < mean: the right tail drags the mean up.
Worked example
the square root of an exponential
X∼Exp(1). Find the density, the mean and the median of Y=X.
Show solutionHide solution
CDF. For y≥0, P(Y≤y)=P(X≤y2)=1−e−y2.
Density. Differentiate: fY(y)=2ye−y2. (Same result from the formula: h(y)=y2, h′(y)=2y, fX(y2)=e−y2.) This is a Rayleigh distribution.
Mean. Substitute x=y2:
E[Y]=E[X1/2]=∫0∞x1/2e−xdx=Γ(23)=2π≈0.886.
Median. Solve 1−e−y2=21: y=ln2≈0.833, which is exactly the square root of the median of X (ln2). The mean, 0.886, is below E[X]=1, as Jensen predicts for the concave square root.
The hard part is the limits of integration: the integrand is non-zero only where bothx and z−x lie in their supports.
Two dice.P(S=s)=366−∣s−7∣ for s=2,…,12: count the pairs on each anti-diagonal.
Two uniforms on [0,1]. The integrand is 1 when 0≤x≤1 and 0≤z−x≤1. The overlap has length z for z≤1 and 2−z for 1≤z≤2: a triangle peaking at z=1.
Normals. The convolution of N(μ1,σ12) and N(μ2,σ22) is N(μ1+μ2,σ12+σ22). Gamma with a common rate and Poisson are also closed under independent sums.
For sums, moment generating functions are often faster than convolving: MX+Y(t)=MX(t)MY(t) for independent X,Y, and you recognise the product.
Worked example
the wait for the second trade
Trades arrive as a Poisson process at rate 1 per minute, so the gaps X1,X2 between trades are independent Exp(1). Find the density of Z=X1+X2, the time of the second trade, and P(Z>2).
Show solutionHide solution
Both densities vanish below 0, so the integrand is non-zero only for 0≤x≤z:
fZ(z)=∫0ze−xe−(z−x)dx=e−z∫0zdx=ze−z,z≥0.
This is Gamma(2, 1). With rate λ the same steps give λ2ze−λz. Integrating by parts,
P(Z>2)=∫2∞ze−zdz=[−ze−z−e−z]2∞=3e−2≈0.406.
Cross-check out loud. The second trade comes after minute 2 exactly when at most one trade happens in the first two minutes. The count is Poisson(2), so the probability is e−2(1+2)=3e−2. The two descriptions agree.
Minima and maxima of independent variables
The max is at most t exactly when every variable is at most t; the min exceeds t exactly when every variable exceeds t. With independence the probabilities multiply:
For n i.i.d. variables with CDF F and density f, the max has density nF(t)n−1f(t). For uniforms, P(max≤t)=tn; for exponentials, P(min>t)=e−(λ1+⋯+λn)t, so the minimum is exponential with the summed rate.
A useful trick for two variables: max(X,Y)=2X+Y+2∣X−Y∣ and min(X,Y)=2X+Y−2∣X−Y∣. Expected maxima then reduce to the expected absolute difference.
Worked example
is a lognormal stock more likely to end up or down?
Under zero rates, a stock follows ST=S0exp(−21σ2T+σTZ) with Z∼N(0,1). Find E[ST], the median of ST, and P(ST>S0) when σ=20% and T=1.
Show solutionHide solution
Here ln(ST/S0)∼N(μ,s2) with μ=−21σ2T and s2=σ2T.
Mean.E[ST]=S0eμ+s2/2=S0e0=S0. The −21σ2T term is there precisely to make the price a martingale.
The stock is fair on average yet ends below its start more often than not: a few large up-moves pay for many small losses. The effect grows with total volatility; at σT=1 the probability of ending up is P(Z>0.5)≈0.309.
Knowledge check
U∼Uniform(0,1). What is the density of Y=U2 at y=0.25?
Knowledge check
X and Y are independent and uniform on [0,1]. What is the density of X+Y at z=1.5?
Knowledge check
X and Y are independent standard normals. What is E[max(X,Y)]?
Knowledge check
lnY∼N(0,1). Which ordering of the mode, median and mean of Y is correct?
Key takeaways
Go through the CDF: write P(g(X)≤y) as a probability about X, then differentiate. It handles non-monotone maps and edge cases that the formula hides.
For monotone g: fY(y)=fX(g−1(y))∣(g−1)′(y)∣. Sum over branches when g is not monotone.
Increasing maps carry quantiles over exactly; they do not carry means (Jensen).
Sums of independent variables convolve; get the integration limits from where both supports overlap, or multiply MGFs.
P(max≤t)=∏Fi(t) and P(min>t)=∏(1−Fi(t)) for independent variables.
Lognormal: median eμ, mean eμ+σ2/2, mode eμ−σ2. A martingale lognormal price ends below its start with probability above one half.