rv (version 2.3.4)

as.logical.rv: Logical Random vectors

Description

Coerces a random variable to a logical-valued one (Bernoulli r.v.)

Usage

# S3 method for rv
as.logical(x, ...)

Arguments

x

an rv object

Further arguments passed on

Details

In effect, the function as.logical is applied to all simulations.

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
# NOT RUN {
  x <- rvbern(prob=0.5)   # some 0/1 valued random variable
  print(x)
  is.logical(x)           # FALSE, because by default x is 'double'
  x <- as.logical(x)      # coerce to logical; all zeros become FALSE, ones become TRUE
  is.logical(x)           # TRUE
  print(x)                # Shows the expectations and not the quantiles

# }

Run the code above in your browser using DataCamp Workspace