10.2 The Inverse Transform Method

Result 10.2.1. To simulate \(X\) with distribution function \(F\): generate \(U\sim \) UNIF\((0,1)\) and return \(X = F^{-1}(U)\). For a discrete distribution taking values \(x_1<x_2<\cdots \) with probabilities \(p_1,p_2,\dots \), return the smallest \(x_k\) for which \(p_1+\cdots +p_k \geq U\).

Example 10.2.2. Give an algorithm to simulate an EXP\((\lambda )\) variable, where \(\lambda \) is the rate.

Solution. Here \(F(x) = 1-e^{-\lambda x}\) for \(x>0\). Solving \(u = 1-e^{-\lambda x}\), \[e^{-\lambda x} = 1-u \quad \Longrightarrow \quad x = -\frac {1}{\lambda }\log (1-u).\] So generate \(U\) and return \(X = -\lambda ^{-1}\log (1-U)\). Since \(1-U\) is also uniform on \((0,1)\), the simpler \(X=-\lambda ^{-1}\log U\) has the same distribution and is what is normally used — one subtraction saved per observation, which matters when millions are drawn.

Note. The method needs \(F^{-1}\) in closed form, which is why it suits the exponential, the Weibull and the Cauchy, and does not suit the normal — whose distribution function has no elementary inverse. That gap is what the next two methods fill.

Questions on this section

Stuck on something here? Ask below and it stays attached to this topic.