5
$\begingroup$

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.

$\endgroup$

1 Answer 1

8
$\begingroup$

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.

$\endgroup$
5
  • 1
    $\begingroup$ +1 -- but it would really help to label the axes in the graphic! $\endgroup$
    – whuber
    Commented Mar 24, 2019 at 23:45
  • 2
    $\begingroup$ @whuber: I agree but could not quickly plot a replacement..! $\endgroup$
    – Xi'an
    Commented Mar 25, 2019 at 7:05
  • $\begingroup$ 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 $\endgroup$ Commented Mar 31, 2019 at 4:43
  • $\begingroup$ 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. $\endgroup$
    – Xi'an
    Commented Mar 31, 2019 at 20:00
  • $\begingroup$ @Xi'an fine ಠ_ಠ $\endgroup$ Commented Apr 3, 2019 at 0:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.