rbernou: Fast Simulation of Bernoulli Random Variables

Description Usage Arguments Details Value Note Author(s) References See Also Examples

View source: R/rbernou.R

Description

The function rbernou generates Bernoulli Random Variables faster than using rbinom(n, 1, prob) or runif(n) <= prob by using a C-level integer comparison.

Usage

1
rbernou(n, prob=0.5)

Arguments

n

integer, number of simulations.

prob

double, probability.

Details

The case prob = 0.5 is twice time faster than the general case 0 <= proba <= 1, using a specific C-level binary algorithm.

Value

A vector of i.i.d. Bernoulli random variables.

Note

For a big number of simulations, it is approximately eleven times faster than the usual rbinom(n, 1, prob).

Author(s)

Nicolas Baradel - PGM Solutions

References

https://en.wikipedia.org/wiki/Bernoulli_distribution

See Also

http://pgm-solutions.com/packages

Examples

1

Example output

[1] 1 1 1 0 1

rpgm documentation built on March 18, 2018, 2:24 p.m.