2

I have a set of probability corresponding to Bernoulli experiment. How to draw Bernoulli random number given these specific probability from a uniform(0,1) distribution. I know we can draw from binom, but using uniform distribution can vectorize the operation and make it so much faster.

MLE
  • 360
  • 1
  • 6
  • 14

1 Answers1

6

It sounds like you're asking how to simulate independent draws from a Bernoulli distribution with a given probability $p$ when all you have is independent draws from a uniform distribution on $[0, 1]$. That's easy: for each value $x$ drawn from the uniform distribution, return 1 if $x < p$ and 0 otherwise.

Kodiologist
  • 20,116
  • Why is that Bernoulli number? Can you explain it a bit more? – MLE Oct 15 '16 at 01:06
  • 1
    Why is the result Bernoulli-distributed, you mean? Because all that's required is to return 1 with probability $p$, and the uniform distribution on $[0, 1]$ means that the chance of $x$ landing in $[0, p]$ is $p$. – Kodiologist Oct 15 '16 at 01:09
  • Yes, why the result is Bernoulli distributed why when x<p, return 1. Still very confused. Why "the uniform distribution on [0,1][0,1] means that the chance of xx landing in [0,p][0,p] is p" – MLE Oct 15 '16 at 01:53
  • Because that's how the uniform distribution is defined. I'm not sure what more there is to say without getting into measure theory or something, which I doubt you would find enlightening. – Kodiologist Oct 15 '16 at 03:05