Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Chapter 13: Functions of Multiple Random Variables

In previous chapters, we explored single random variables and then pairs or groups of random variables (joint distributions, covariance, correlation). Now, we take the next step: what happens when we combine multiple random variables using mathematical functions?

For example, if XX represents the revenue from product A and YY represents the revenue from product B, we might be interested in the distribution of the total revenue Z=X+YZ = X + Y. Or, if XX and YY are coordinates, we might want to know the distribution of the distance from the origin, R=X2+Y2R = \sqrt{X^2 + Y^2}.

This chapter explores methods for finding the distributions of such combined variables, focusing on sums, differences, products, ratios, general transformations, and order statistics. We’ll see how theoretical results can be derived and how simulation can provide empirical insights, especially when analytical solutions are complex.

Distributions of Sums, Differences, Products, and Ratios

One of the most common operations is finding the distribution of the sum of two or more random variables.

Sums of Independent Random Variables

Let XX and YY be two independent random variables, and let Z=X+YZ = X + Y. Finding the distribution of ZZ involves a technique called convolution.

Differences, Products, and Ratios

Finding the distributions for differences (Z=XYZ=X-Y), products (Z=XYZ=XY), or ratios (Z=X/YZ=X/Y) can also be done using transformations or convolution-like methods, but the formulas can become more complex.

For many complex functions or when analytical derivation is intractable, simulation becomes a powerful tool to approximate the resulting distribution.

Introduction to Multivariate Transformations

Suppose we have a pair of random variables (X,Y)(X, Y) with a known joint PDF fX,Y(x,y)f_{X,Y}(x, y). We define two new random variables U=g1(X,Y)U = g_1(X, Y) and V=g2(X,Y)V = g_2(X, Y). How do we find the joint PDF of (U,V)(U, V), denoted fU,V(u,v)f_{U,V}(u, v)?

This requires a technique analogous to the change of variables in multivariable calculus, using the Jacobian of the transformation.

  1. Solve for Original Variables: Express xx and yy in terms of uu and vv: x=h1(u,v)x = h_1(u, v) and y=h2(u,v)y = h_2(u, v).

  2. Calculate the Jacobian Determinant: The Jacobian determinant JJ is:

    J=det(xuxvyuyv)=xuyvxvyuJ = \det \begin{pmatrix} \frac{\partial x}{\partial u} & \frac{\partial x}{\partial v} \\ \frac{\partial y}{\partial u} & \frac{\partial y}{\partial v} \end{pmatrix} = \frac{\partial x}{\partial u}\frac{\partial y}{\partial v} - \frac{\partial x}{\partial v}\frac{\partial y}{\partial u}
  3. Apply the Transformation Formula: The joint PDF of (U,V)(U, V) is:

    fU,V(u,v)=fX,Y(h1(u,v),h2(u,v))Jf_{U,V}(u, v) = f_{X,Y}(h_1(u, v), h_2(u, v)) \cdot |J|

    where J|J| is the absolute value of the Jacobian determinant. This formula is valid provided the transformation is one-to-one over the region of interest.

Example: Cartesian to Polar Coordinates. Let (X,Y)(X, Y) have a joint PDF fX,Y(x,y)f_{X,Y}(x, y). Consider the transformation to polar coordinates: R=X2+Y2R = \sqrt{X^2 + Y^2} and Θ=arctan(Y/X)\Theta = \arctan(Y/X). We want to find the joint PDF fR,Θ(r,θ)f_{R,\Theta}(r, \theta). The inverse transformation is x=rcosθx = r \cos \theta and y=rsinθy = r \sin \theta. The Jacobian determinant is:

J=det(cosθrsinθsinθrcosθ)=(cosθ)(rcosθ)(rsinθ)(sinθ)=rcos2θ+rsin2θ=rJ = \det \begin{pmatrix} \cos \theta & -r \sin \theta \\ \sin \theta & r \cos \theta \end{pmatrix} = (\cos \theta)(r \cos \theta) - (-r \sin \theta)(\sin \theta) = r \cos^2 \theta + r \sin^2 \theta = r

Assuming r>0r > 0, J=r|J| = r. Thus:

fR,Θ(r,θ)=fX,Y(rcosθ,rsinθ)rf_{R,\Theta}(r, \theta) = f_{X,Y}(r \cos \theta, r \sin \theta) \cdot r

If X,YN(0,1)X, Y \sim N(0, 1) independently, then fX,Y(x,y)=12πe(x2+y2)/2f_{X,Y}(x, y) = \frac{1}{2\pi} e^{-(x^2+y^2)/2}. Substituting x=rcosθ,y=rsinθx = r \cos \theta, y = r \sin \theta, we get x2+y2=r2x^2+y^2 = r^2. So, fR,Θ(r,θ)=12πer2/2rf_{R,\Theta}(r, \theta) = \frac{1}{2\pi} e^{-r^2/2} \cdot r. We can see this separates into a function of rr and θ\theta, indicating RR and Θ\Theta are independent. Integrating over θ\theta from 0 to 2π2\pi gives the marginal PDF for RR: fR(r)=rer2/2f_R(r) = r e^{-r^2/2} for r>0r > 0 (Rayleigh distribution), and integrating over rr gives the marginal PDF for Θ\Theta: fΘ(θ)=12πf_\Theta(\theta) = \frac{1}{2\pi} for 0θ<2π0 \le \theta < 2\pi (Uniform distribution).

Order Statistics

Suppose we have a sample of nn independent and identically distributed (i.i.d.) random variables X1,X2,,XnX_1, X_2, \dots, X_n. If we arrange these variables in ascending order, we get the order statistics: X(1),X(2),,X(n)X_{(1)}, X_{(2)}, \dots, X_{(n)}, where X(1)=min(X1,,Xn)X_{(1)} = \min(X_1, \dots, X_n) and X(n)=max(X1,,Xn)X_{(n)} = \max(X_1, \dots, X_n).

We are often interested in the distribution of these order statistics, particularly the minimum (X(1)X_{(1)}) and the maximum (X(n)X_{(n)}).

Let the common CDF and PDF of the XiX_i be F(x)F(x) and f(x)f(x), respectively.

Example: Let X1,,XnX_1, \dots, X_n be i.i.d. Exponential(λ)Exponential(\lambda). Then F(x)=1eλxF(x) = 1 - e^{-\lambda x} for x0x \ge 0. The CDF of the minimum is FX(1)(x)=1[1(1eλx)]n=1[eλx]n=1enλxF_{X_{(1)}}(x) = 1 - [1 - (1 - e^{-\lambda x})]^n = 1 - [e^{-\lambda x}]^n = 1 - e^{-n\lambda x}. This is the CDF of an Exponential(nλ)Exponential(n\lambda) distribution. So, the minimum of nn i.i.d. exponential random variables is also exponential, with a rate nn times the original rate.

Hands-on: Simulations and Comparisons

Simulating the Sum of Two Independent Uniform Random Variables

We expect the sum of two independent Uniform(0,1)Uniform(0, 1) variables to follow a triangular distribution on (0,2)(0, 2), with PDF:

fZ(z)={z0z12z1<z20otherwisef_Z(z) = \begin{cases} z & 0 \le z \le 1 \\ 2-z & 1 < z \le 2 \\ 0 & \text{otherwise} \end{cases}

Let’s simulate this and compare the histogram of the simulated sums to the theoretical PDF.

import numpy as np
import matplotlib.pyplot as plt
import scipy.stats as stats

# --- Simulation Parameters ---
num_simulations = 100000

# --- Simulate Uniform Random Variables ---
# Generate pairs of independent Uniform(0, 1) variables
X = np.random.rand(num_simulations)
Y = np.random.rand(num_simulations)

# --- Calculate the Sum ---
Z = X + Y

# --- Define the Theoretical PDF ---
def triangular_pdf(z):
    if 0 <= z <= 1:
        return z
    elif 1 < z <= 2:
        return 2 - z
    else:
        return 0

# Vectorize the function for plotting
v_triangular_pdf = np.vectorize(triangular_pdf)

# --- Plotting ---
plt.figure(figsize=(10, 6))

# Plot histogram of simulated sums
plt.hist(Z, bins=50, density=True, alpha=0.7, label=f'Simulated Sums (n={num_simulations})')

# Plot theoretical PDF
z_values = np.linspace(0, 2, 400)
pdf_values = v_triangular_pdf(z_values)
plt.plot(z_values, pdf_values, 'r-', lw=2, label='Theoretical Triangular PDF')

plt.title('Sum of Two Independent Uniform(0, 1) Variables')
plt.xlabel('Z = X + Y')
plt.ylabel('Density')
plt.legend()
plt.grid(True, linestyle='--', alpha=0.6)
plt.show()
<Figure size 1000x600 with 1 Axes>

Simulating Order Statistics: Minimum of Exponential Variables

Let’s simulate the minimum of n=5n=5 independent Exponential(λ=1)Exponential(\lambda=1) random variables. We derived theoretically that X(1)Exponential(nλ=5)X_{(1)} \sim Exponential(n\lambda = 5). Let’s verify this visually.

import numpy as np
import matplotlib.pyplot as plt
import scipy.stats as stats

# --- Simulation Parameters ---
num_simulations = 100000
n_variables = 5  # Number of exponential variables
lambda_rate = 1.0 # Rate parameter for individual variables

# --- Simulate Exponential Random Variables ---
# Generate n_variables sets of exponential random variables
# Each row is a simulation, each column is one X_i
exp_samples = np.random.exponential(scale=1.0/lambda_rate, size=(num_simulations, n_variables))

# --- Calculate the Minimum for each simulation ---
X_min = np.min(exp_samples, axis=1)

# --- Theoretical Distribution ---
# The minimum follows Exponential(n * lambda)
theoretical_rate = n_variables * lambda_rate
theoretical_dist = stats.expon(scale=1.0/theoretical_rate)

# --- Plotting ---
plt.figure(figsize=(10, 6))

# Plot histogram of simulated minimums
plt.hist(X_min, bins=50, density=True, alpha=0.7, label=f'Simulated Minima (n={n_variables}, $\lambda$={lambda_rate})')

# Plot theoretical PDF
x_values = np.linspace(X_min.min(), X_min.max(), 400)
pdf_values = theoretical_dist.pdf(x_values)
plt.plot(x_values, pdf_values, 'r-', lw=2, label=f'Theoretical Exponential PDF (rate={theoretical_rate:.1f})')

plt.title(f'Distribution of the Minimum of {n_variables} i.i.d. Exponential({lambda_rate}) Variables')
plt.xlabel('Value of Minimum ($X_{(1)}$)')
plt.ylabel('Density')
plt.legend()
plt.grid(True, linestyle='--', alpha=0.6)
plt.show()
<Figure size 1000x600 with 1 Axes>

Summary

This chapter introduced methods for finding the distribution of functions of multiple random variables. We specifically looked at:

We used simulations to empirically verify theoretical results, such as the triangular distribution arising from the sum of two uniforms and the exponential distribution arising from the minimum of exponentials. Simulation is a crucial tool when analytical derivations become too complex or intractable.

Exercises

  1. Sum of Two Poissons: Let XPoisson(2)X \sim Poisson(2) and YPoisson(3)Y \sim Poisson(3) be independent. a. What is the distribution of Z=X+YZ = X + Y? b. Calculate P(Z=4)P(Z=4). c. Simulate XX and YY many times, calculate their sum ZZ, and create a histogram of the simulated ZZ values. Compare the histogram to the theoretical PMF from part (a).

  2. Maximum of Uniforms: Let U1,U2,U3U_1, U_2, U_3 be i.i.d. Uniform(0,1)Uniform(0, 1). a. Find the theoretical CDF and PDF of U(3)=max(U1,U2,U3)U_{(3)} = \max(U_1, U_2, U_3). b. Simulate U1,U2,U3U_1, U_2, U_3 many times, find the maximum in each simulation, and create a histogram. Compare it to the theoretical PDF from part (a).

  3. Ratio of Normals (Cauchy Distribution): Let XN(0,1)X \sim N(0, 1) and YN(0,1)Y \sim N(0, 1) be independent. Simulate XX and YY many times and compute the ratio Z=X/YZ = X/Y. Plot a histogram of the ZZ values. What distribution does this resemble? (Note: The theoretical distribution is the Cauchy distribution, which has unusual properties like an undefined mean.)