4
$\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$
4
$\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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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