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

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.

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$$

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)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.

• +1 -- but it would really help to label the axes in the graphic! – whuber Mar 24 '19 at 23:45
• @whuber: I agree but could not quickly plot a replacement..! – Xi'an Mar 25 '19 at 7:05
• Thank you prof. Xi'an, could you tell me how can this be implemented in r ? As far as I understand there is a loop which I don't know how exactly to set – I likeThatMeow Mar 31 '19 at 4:43
• I am afraid not, as I fear it would not help you in the long run. The principle is rather clearly stated, with enough details to achieve an R implementation. – Xi'an Mar 31 '19 at 20:00
• @Xi'an fine ಠ_ಠ – I likeThatMeow Apr 3 '19 at 0:02