2
$\begingroup$

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.

$\endgroup$
0

1 Answer 1

6
$\begingroup$

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.

$\endgroup$
4
  • $\begingroup$ Why is that Bernoulli number? Can you explain it a bit more? $\endgroup$
    – MLE
    Oct 15, 2016 at 1:06
  • 1
    $\begingroup$ 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$. $\endgroup$ Oct 15, 2016 at 1:09
  • $\begingroup$ 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" $\endgroup$
    – MLE
    Oct 15, 2016 at 1:53
  • $\begingroup$ 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. $\endgroup$ Oct 15, 2016 at 3:05

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