Theory Tuesday- Generating a Random Number from any Probability Distribution

Assumption: You can generate X, a random number from a Uniform[0,1] Distribution. There are many ways to do that.

The objective is to turn X, which is uniformly distributed between 0 and 1, into Y, which is a random number from a probability distribution of your choosing. Examples of probability distributions are the Normal Distribution, Exponential Distribution, and Beta Distributions.

Key insight: All probability values are between 0 and 1. The cumulative distribution function (CDF) for a probability distribution gives the percent of the distribution that is below a value in the distribution. Take X, the number in Uniform[0,1], and transform it into Y, a value in your distribution of interest that has CDF X.

Example: Say you generate X=.766 and want a random number, Y, from the standard normal distribution (mean=0, standard deviation=1). Abbreviate the standard normal distribution as N[0,1]. Let F(x) be the CDF of N[0,1]. To generate Y~N[0,1], we need to find Y=F^{-1}(X), where F^{-1} is the inverse of the CDF. We can look up F^{-1}(X)=F^{-1}(.766) in a normal distribution table or by using the function norm.inv(.766,0,1) in Excel. We find that the value of interest is Y=.7257.

For distributions whose CDF is invertible, we can find equations for Y, the random number from the distribution. Take the exponential distribution for example. The CDF of the exponential distribution with mean 1/\lambda is F(y)=1-e^{-\lambda y}. Solve F(y)=x for y. We find y=F^{-1}(x)=\frac{-\ln(1-x)}{\lambda}. Now, when we generate any X~U[0,1], we can use the equation for F^{-1}(X) to find Y, which is a random number from the exponential distribution.

For distributions whose CDF is not continuous, you will want to find the smallest Y who has a CDF of at least X.

Leave a Reply

Your email address will not be published. Required fields are marked *