Learn R Programming

rv (version 2.0.0)

rvbern: Generate a Random Vector from a Bernoulli Sampling Model

Description

rvbern generates a random vector where each simulation comes from a Bernoulli sampling distribution.

Usage

rvbern(n=1, prob, logical=FALSE)

Arguments

n
number of random scalars to draw
prob
probability of ``success''; may be a random vector itself
logical
logical; return a logical random variable instead

Value

  • A random vector (an rv object) of length n.

Details

rvbern is a special case of rvbinom with the argument size=1.

If logical is TRUE, the function returns a logical random variable which has TRUE for 1, FALSE for 0. (The printed summary of this object is slightly different from a regular continuous numeric random variable.)

References

Kerman, J. and Gelman, A. (2007). Manipulating and Summarizing Posterior Simulations Using Random Variable Objects. Statistics and Computing 17:3, 235-244.

See also vignette("rv").

Examples

Run this code
rvbern(2, prob=0.5)
  rvbinom(2, size=1, prob=0.5) # Equivalent
  print(rvbern(1, 0.5, logical=TRUE)) # won't show the quantiles
  print(as.logical(rvbern(1, 0.5))) # equivalent

Run the code above in your browser using DataLab