Simulate a random sample from the Bernoulli distribution.

psi.rbern(n, p)

Arguments

n

number of observations.

p

probability of success.

Details

A random variable has the Bernoulli(p) distribution if takes the value one with probability \(p\) and the value zero with probability \(1-p\).

The Bernoulli(p) distribution is a particular case of the binomial distribution with \(n=1\).

Value

a numeric vector representing a random sample from Bernoulli(p)

Examples

psi.rbern(10, 0.5) # 10 draws of a fair coin
#> [1] 1 0 1 0 1 1 0 0 0 0
psi.rbern(10, 0.6) # 10 draws of a biased coin
#> [1] 0 0 1 1 0 0 1 1 0 1
# eqivalent to the above (but don't expect identical results!) rbinom(10, size = 1, prob = 0.5)
#> [1] 0 0 0 1 1 0 1 0 0 0
rbinom(10, size = 1, prob = 0.6)
#> [1] 1 1 1 1 1 1 1 0 0 0