No history yet

Random Variable Mechanics

The Engine of Randomness

To simulate random events, we need more than just a coin flip. We need a precise way to describe and measure randomness. The two most important measures are the expected value and the variance of a random variable.

The expected value, or mean, is the long-run average value of a random variable. It's the center of the distribution.

For a discrete random variable XX that can take on values x1,x2,...x_1, x_2, ... with probabilities P(x1),P(x2),...P(x_1), P(x_2), ..., the expected value E[X]E[X] is the sum of each value multiplied by its probability.

E[X]=ixiP(X=xi)E[X] = \sum_{i} x_i P(X=x_i)

For a continuous random variable, we can't just sum up the probabilities of individual points because the probability of any single exact value is zero. Instead, we use an integral. We integrate the variable's value, xx, multiplied by its probability density function, f(x)f(x), across all possible values.

E[X]=xf(x)dxE[X] = \int_{-\infty}^{\infty} x f(x) \,dx

Variance measures the spread of a distribution. A low variance means the values are clustered tightly around the mean, while a high variance means they are spread out. It's formally defined as the expected value of the squared difference between the variable and its mean, μ=E[X]\mu = E[X].

Var(X)=E[(Xμ)2]\text{Var}(X) = E[(X - \mu)^2]

Just like with expectation, this leads to two formulas. For discrete variables, we use a sum:

Var(X)=i(xiμ)2P(X=xi)\text{Var}(X) = \sum_{i} (x_i - \mu)^2 P(X=x_i)

And for continuous variables, we use an integral:

Var(X)=(xμ)2f(x)dx\text{Var}(X) = \int_{-\infty}^{\infty} (x - \mu)^2 f(x) \,dx

Describing Randomness

Expected value and variance summarize a distribution, but they don't tell the whole story. To fully describe a random variable, we use probability functions.

For a continuous random variable, this is the Probability Density Function (PDF), denoted f(x)f(x). The PDF doesn't give you the probability of a specific value. Instead, the area under the curve between two points gives the probability that the variable will fall within that range.

Lesson image

A related concept is the Cumulative Distribution Function (CDF), denoted F(x)F(x). The CDF gives the total probability that the random variable XX will take on a value less than or equal to xx. It's the accumulated probability up to that point.

For any continuous variable, the CDF is simply the integral of the PDF from negative infinity up to xx.

F(x)=P(Xx)=xf(t)dtF(x) = P(X \le x) = \int_{-\infty}^{x} f(t) \,dt

The CDF always ranges from 0 to 1. It starts at 0 for very small values of xx and climbs to 1 as xx increases, capturing all possible outcomes.

Shaping Randomness

Computers are great at generating random numbers, but they usually produce them from a uniform distribution, where every number between 0 and 1 is equally likely. What if we need numbers that follow a normal (bell curve) distribution or some other shape?

This is where we need to transform variables. The most fundamental technique for this is the Inverse Transform Method. It's a clever way to turn uniform random numbers into random numbers from any other distribution, as long as we know its CDF.

The method works by mapping a uniform random number through the inverse of the target distribution's CDF.

Here’s the process:

  1. Generate a random number, uu, from a Uniform(0, 1) distribution.
  2. Find the CDF, F(x)F(x), of the distribution you want to generate numbers from (e.g., Normal, Exponential).
  3. Calculate the inverse of that CDF, which we write as F1(y)F^{-1}(y).
  4. Apply this inverse function to your random number uu. The result, x=F1(u)x = F^{-1}(u), will be a random number that follows your target distribution.

This method is the mathematical heart of generating the random inputs needed for Monte Carlo simulations. By starting with a simple, universally available random source (the uniform distribution), we can create samples that mimic almost any random process we want to study.

DistributionTypePDF / PMFExpected Value (μ)Variance (σ²)
Uniform(a, b)Continuousf(x)=1baf(x) = \frac{1}{b-a}a+b2\frac{a+b}{2}(ba)212\frac{(b-a)^2}{12}
Normal(μ, σ²)Continuousf(x)=1σ2πe(xμ)22σ2f(x) = \frac{1}{\sigma\sqrt{2\pi}} e^{-\frac{(x-\mu)^2}{2\sigma^2}}μ\muσ2\sigma^2
Bernoulli(p)DiscreteP(X=k)=pk(1p)1kP(X=k) = p^k(1-p)^{1-k} for k{0,1}k \in \{0,1\}ppp(1p)p(1-p)

Now, let's test your understanding of these core mechanics.

Quiz Questions 1/5

What does the expected value of a random variable represent?

Quiz Questions 2/5

A low variance for a random variable indicates that its values are spread out widely from the mean.

With these mathematical tools, we can precisely define, measure, and generate the randomness that powers stochastic simulations.