Concatentates random vectors.

cc(..., recursive = FALSE)

# S3 method for rv
c(..., recursive = FALSE)

Arguments

...

objects to be concatenated. Can be a mixture of constants and rv objects.

recursive

logical. If recursive = TRUE, the function recursively descends through lists (and pairlists) combining all their elements into a vector.

Details

NOTE: recursive has not yet been tested.

cc is a function that works for both non-rv and other vectors. To make code compatible for both constant vectors and rv objects, one can use cc instead of c.

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 <- rvnorm(2)
  y <- rvbern(2, prob=0.5)
  z <- c(x, y)
  print(z)
#>       mean   sd   1% 2.5%   25%    50%  75% 97.5% 99% sims
#> [1] -0.019 0.98 -2.2 -1.9 -0.68 -0.028 0.63   1.9 2.3 4000
#> [2] -0.014 1.00 -2.4 -1.9 -0.69 -0.012 0.66   1.9 2.3 4000
#> [3]  0.488 0.50  0.0  0.0  0.00  0.000 1.00   1.0 1.0 4000
#> [4]  0.516 0.50  0.0  0.0  0.00  1.000 1.00   1.0 1.0 4000
  z1 <- cc(1, z)
  z2 <- c(as.rv(1), z)
  z3 <- c(as.rv(1), z)
  print(z1)
#>       mean   sd   1% 2.5%   25%    50%  75% 97.5% 99% sims
#> [1]  1.000 0.00  1.0  1.0  1.00  1.000 1.00   1.0 1.0    1
#> [2] -0.019 0.98 -2.2 -1.9 -0.68 -0.028 0.63   1.9 2.3 4000
#> [3] -0.014 1.00 -2.4 -1.9 -0.69 -0.012 0.66   1.9 2.3 4000
#> [4]  0.488 0.50  0.0  0.0  0.00  0.000 1.00   1.0 1.0 4000
#> [5]  0.516 0.50  0.0  0.0  0.00  1.000 1.00   1.0 1.0 4000
  print(z2)
#>       mean   sd   1% 2.5%   25%    50%  75% 97.5% 99% sims
#> [1]  1.000 0.00  1.0  1.0  1.00  1.000 1.00   1.0 1.0    1
#> [2] -0.019 0.98 -2.2 -1.9 -0.68 -0.028 0.63   1.9 2.3 4000
#> [3] -0.014 1.00 -2.4 -1.9 -0.69 -0.012 0.66   1.9 2.3 4000
#> [4]  0.488 0.50  0.0  0.0  0.00  0.000 1.00   1.0 1.0 4000
#> [5]  0.516 0.50  0.0  0.0  0.00  1.000 1.00   1.0 1.0 4000
  print(z3)
#>       mean   sd   1% 2.5%   25%    50%  75% 97.5% 99% sims
#> [1]  1.000 0.00  1.0  1.0  1.00  1.000 1.00   1.0 1.0    1
#> [2] -0.019 0.98 -2.2 -1.9 -0.68 -0.028 0.63   1.9 2.3 4000
#> [3] -0.014 1.00 -2.4 -1.9 -0.69 -0.012 0.66   1.9 2.3 4000
#> [4]  0.488 0.50  0.0  0.0  0.00  0.000 1.00   1.0 1.0 4000
#> [5]  0.516 0.50  0.0  0.0  0.00  1.000 1.00   1.0 1.0 4000