rbernoulli {simDAG}R Documentation

Generate Random Draws from a Bernoulli Distribution

Description

A very fast implementation for generating bernoulli trials. Can take a vector of probabilities which makes it very useful for simulation studies.

Usage

rbernoulli(n, p=0.5)

Arguments

n

How many draws to make.

p

A numeric vector of probabilities, used when drawing the trials.

Details

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.

Value

Returns a logical vector of length n.

Author(s)

Robin Denz

Examples

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))

[Package simDAG version 0.1.2 Index]