Solved – How does the inverse transform method work in discrete r.v.

rrandom variablesimulationtransformuniform distribution

In this question How does the inverse transform method work? it's mentioned the general procedure to generate r.v.

U <- runif(1e6)
X <- qnorm(U)
X

How would that change for the discrete case?

How does the inverse transform method work in discrete r.v.?

If someone could explain detailed as the answer given in the other question, that would be great.

Best Answer

The inverse cdf method also operates for discrete support distributions: by defining the generalised inverse as $$F^{-1}(u)=\inf\{x;\ F(x)\ge u\}$$ the distribution of $F^{-1}(U)$ is $F$ when $U$ is Uniform(0,1), as in the image below for a Poisson distribution (from Wolfram):

$\qquad\qquad$enter image description here

The reason is that $$\Bbb P(F^{-1}(U)\le x)=\Bbb P(U\le F(x))=F(x)$$

For instance, if $F$ is supported by integers, like a Poisson distribution, and if$$U\le F(0)=\Bbb P(X=0)$$then $F^{-1}(U)=0$. Similarly, if$$ F(0)<U\le F(1)=\Bbb P(X=0)+\Bbb P(X=1)$$then $F^{-1}(U)=1$. And so on.

Another way to look at the same answer: if $X$ is distributed on the integers with probabilities $p_0$, $p_1$, &tc., simulating a realisation of $X$ means selecting $0$ with probability $p_0$, $1$ with probability $p_1$, &tc. Hence, to implement the simulation, one need generate a Uniform (0,1) variate u and, if $u\le p_0$ [which happens with probability $p_0$], set $X=0$, else if $p_0< u\le p_0+p_1$ [which happens with probability $p_1$], set $X=1$, &tc.