psi.rbern: Simulate a random sample from Bernoulli distribution

Description Usage Arguments Details Value Author(s) Examples

View source: R/psistat.R

Description

Simulate a random sample from the Bernoulli distribution.

Usage

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

Author(s)

Georgi N. Boshnakov (but note that this function is a simple wrapper for rbinom from core R)

Examples

1
2
3
4
5
6
psi.rbern(10, 0.5)   # 10 draws of a fair coin
psi.rbern(10, 0.6)   # 10 draws of a biased coin

# eqivalent to the above (but don't expect identical results!)
rbinom(10, size = 1, prob = 0.5)
rbinom(10, size = 1, prob = 0.6)

GeoBosh/psistat documentation built on Nov. 19, 2020, 8:19 p.m.