# Difference between revisions of "stat341 / CM 361"

Computational Statistics and Data Analysis is a course offered at the University of Waterloo
Spring 2009
Instructor: Ali Ghodsi

## Sampling (Generating Random numbers)

### Inverse Transform Method

Step 1: Draw $U~ \sim~ Unif [0,1]$.
Step 2: Compute $X = F^{-1}(U)$.
Example:
Suppose we want to draw a sample from $f(x) = \lambda e^{-\lambda x}$ where $x\gt 0$.
We need to first find $F(x)$ and then $F^{-1}$.

$F(x) = \int^x_0 \theta e^{-\theta u} du = 1 - e^{-\theta x}$


$F^{-1}(x) = \frac{-log(1-y)}{\theta}$
Now we can generate our random sample $i=1\dots n$ from $f(x)$ by:

$1)\ u_i \sim UNIF(0,1)$
$2)\ x_i = \frac{-log(1-u_i)}{\theta}$


The $x_i$ are now a random sample from $f(x)$.
The major problem with this approach is that we have to find $F^{-1}$ and for many distributions it is too difficult to find the inverse of $F(x)$.