Interactive demo · Probability and Statistical Inference · Chapter 2

Inverse-cdf sampling: from uniforms to any distribution

Draw U uniformly on (0, 1) and return X = F−1(U), the smallest x with F(x) > U. Then X has cdf F, whatever F is: continuous, discrete, a mixture of both, or the empirical cdf of a data set. Where F is steep, many uniforms land on few values of x; a jump of height f(k) catches every uniform in an interval of that length; a flat stretch of F receives no draws at all.

Distribution F

Parameter

Number of draws n

Probe a level u

Try these

The uniforms come from a seeded generator, so a preset always shows the same draws ("new uniforms" moves to the next seed). The quantile function follows the book's convention inf{x : F(x) > u}; the readout also gives inf{x : F(x) ≥ u}, which differs only at levels u where F is flat. Dn is the largest vertical gap between the empirical cdf of the draws and F. Nerve data: 799 waiting times (seconds) between nerve pulses, from the book's website; "Exp fit" uses the Exp(β) law with β equal to their mean.

In the lecture notes