Creates or tests for objects of type "rvfactor".

# S3 method for rvfactor
print(x, all.levels = FALSE, ...)

rvfactor(x, ...)

# S3 method for default
rvfactor(x, levels = NULL, ...)

Arguments

x

object to be coerced or tested.

all.levels

logical; whether to print all levels or not (see below for details)

...

other arguments

levels

factor levels (labels for the levels)

Value

rvfactor: an rvfactor object. is.rvfactor: TRUE or FALSE. as.rv.rvfactor: an rv object. as.rvfactor.rv: an rvfactor object.

Details

Internally random factors are integer-valued just like regular factors in R.

The number of levels to print when all.levels==FALSE can be set by rvpar(max.levels=...). By default this is set to 10.

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


  # Probabilities of each integer of trunc(Z) where Z ~ N(0,1) ?
  x <- rvnorm(1)
  rvfactor(trunc(x))
#>        -2    -1     0   1     2 sims
#> [1] 0.015 0.145 0.725 0.1 0.015  200
  rvfactor(x>0)
#>     FALSE  TRUE sims
#> [1] 0.505 0.495  200
  rvfactor(rvpois(1, lambda=0.5))
#>         0     1    2    3 sims
#> [1] 0.635 0.295 0.06 0.01  200