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

# 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.

Note

is.logical(x) returns TRUE if and only if each component of x is logical-valued (i.e. TRUE/FALSE).

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").

Author

Jouni Kerman jouni@kerman.com

Examples


  x <- rvbern(prob=0.5)   # some 0/1 valued random variable
  print(x)
#>     mean  sd 1% 2.5% 25% 50% 75% 97.5% 99% sims
#> [1] 0.49 0.5  0    0   0   0   1     1   1 4000
  is.logical(x)           # FALSE, because by default x is 'double'
#> [1] FALSE
  x <- as.logical(x)      # coerce to logical; all zeros become FALSE, ones become TRUE
  is.logical(x)           # TRUE
#> [1] FALSE
  print(x)                # Shows the expectations and not the quantiles
#>     mean  sd 1% 2.5% 25% 50% 75% 97.5% 99% sims
#> [1] 0.49 0.5  0    0   0   0   1     1   1 4000