rbernoulli {simDAG} | R Documentation |
A very fast implementation for generating bernoulli trials. Can take a vector of probabilities which makes it very useful for simulation studies.
rbernoulli(n, p=0.5)
n |
How many draws to make. |
p |
A numeric vector of probabilities, used when drawing the trials. |
Internally, it uses only a single call to runif
, making it much faster and more memory efficient than using rbinomial
.
Note that this function accepts values of p
that are smaller then 0 and greater than 1. For p < 0
it will always return FALSE
, for p > 1
it will always return TRUE
.
Returns a logical vector of length n
.
Robin Denz
library(simDAG)
# generating 5 bernoulli random draws from an unbiased coin
rbernoulli(n=5, p=0.5)
# using different probabilities for each coin throw
rbernoulli(n=5, p=c(0.1, 0.2, 0.3, 0.2, 0.7))