Simulation of unlikely events over random binary variables knowing their probability

#1
Hi,

I have n binary variables all having the same probability p of flipping. Probability is low, so I wouldn't want to go through generating a random number for every one of them in order to flip their value. I know that the expected number of flips for the n variables is m = n*p. I could use this number to generate m random indexes and proceed by flipping the variables indexed by them, but somehow I'm not quite satisfied with it because in a random process it will not be always the case that m elements will be flipped. Is there an efficient way to simulate the variance around m?

Thank you!

Stan
 
Last edited:
#2
Re: Simulation of unlikely events over random binary variables knowing their probabil

I guess I can simulate a binomial distribution, isn't it?

The probability of none flipping is (1-p)^n * p^0 * combinations(n,0)
The probability of one flipping is (1-p)^(n-1) * p^1 * combinations(n,1)
and so on...
The probability of all flipping is (1-p)^0 * p^n * combinations(n,n)

All I need to do is simulate a binomial, to generate the number of flips to perform.
 
#3
Re: Simulation of unlikely events over random binary variables knowing their probabil

found that one way to simulate random variables with binomial distribution is exactly what I was trying to avoid... surely there must be a better way!
 

BGM

TS Contributor
#4
Re: Simulation of unlikely events over random binary variables knowing their probabil

I think most of the statistical software can generate Binomial variate quite efficiently.

If you are looking for the algorithm behind, you may take a look at the manual.

For example, in R, for the command rbinom() it cited

Kachitvichyanukul, V. and Schmeiser, B. W. (1988) Binomial random variate generation. Communications of the ACM, 31, 216–222.

For larger values it uses inversion.
In fact I think inversion will not too inefficient, because the mode (close to the mean) is small also when \( p \) is small.