I wish to generate random binary outcome with a given probability of 0.05. So in average I should get a positive (1) and 19 negatives (0) every 20 draws.
How can I do that with R ?
I see how I can generate with a 0.5 probability:
sample(0:1, 10000, replace=T)
mean(sample(0:1, 10000, replace=T))
[1] 0.5034
But I would need a probability of 0.05.
There is a random generator for the binomial distribution whose purpose is exactly to generate such samples:
x <- rbinom(n=10000, size=1, prob=0.05)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With