Mathematical functions and operators adapted to work with random variable (rv) objects.
object
further arguments passed to or from other methods
object
object
The operator method preserves the names of the longer vector (or those of the first if the lengths match).
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")
.
x <- rvnorm(10)
-x
#> mean sd 1% 2.5% 25% 50% 75% 97.5% 99% sims
#> [1] 0.0062 0.99 -2.2 -1.9 -0.66 0.0027 0.67 1.9 2.3 4000
#> [2] -0.0093 1.00 -2.3 -2.0 -0.68 -0.0231 0.68 1.9 2.3 4000
#> [3] 0.0057 0.99 -2.4 -2.0 -0.64 -0.0101 0.67 2.0 2.3 4000
#> [4] -0.0014 0.99 -2.3 -1.9 -0.67 0.0066 0.69 1.9 2.3 4000
#> [5] -0.0013 0.99 -2.3 -2.0 -0.66 0.0048 0.68 1.9 2.2 4000
#> [6] 0.0434 1.01 -2.2 -2.0 -0.63 0.0401 0.71 2.0 2.4 4000
#> [7] 0.0056 0.98 -2.3 -1.9 -0.66 0.0181 0.68 1.9 2.3 4000
#> [8] -0.0035 0.99 -2.3 -2.0 -0.66 -0.0041 0.66 1.9 2.3 4000
#> [9] -0.0015 0.99 -2.3 -2.0 -0.67 -0.0057 0.66 2.0 2.3 4000
#> [10] -0.0245 0.99 -2.3 -1.9 -0.71 -0.0266 0.62 1.9 2.3 4000
names(x) <- paste("x[", seq_along(x), "]", sep="")
x + 1:10
#> name mean sd 1% 2.5% 25% 50% 75% 97.5% 99% sims
#> [1] x[1] 0.99 0.99 -1.31 -0.94 0.33 1 1.7 2.9 3.2 4000
#> [2] x[2] 2.01 1.00 -0.34 0.08 1.32 2 2.7 4.0 4.3 4000
#> [3] x[3] 2.99 0.99 0.68 1.00 2.33 3 3.6 5.0 5.4 4000
#> [4] x[4] 4.00 0.99 1.73 2.06 3.31 4 4.7 5.9 6.3 4000
#> [5] x[5] 5.00 0.99 2.78 3.09 4.32 5 5.7 7.0 7.3 4000
#> [6] x[6] 5.96 1.01 3.61 3.96 5.29 6 6.6 8.0 8.2 4000
#> [7] x[7] 6.99 0.98 4.73 5.08 6.32 7 7.7 8.9 9.3 4000
#> [8] x[8] 8.00 0.99 5.70 6.09 7.34 8 8.7 10.0 10.3 4000
#> [9] x[9] 9.00 0.99 6.69 7.04 8.34 9 9.7 11.0 11.3 4000
#> [10] x[10] 10.02 0.99 7.65 8.07 9.38 10 10.7 11.9 12.3 4000
1:2 + x
#> name mean sd 1% 2.5% 25% 50% 75% 97.5% 99% sims
#> [1] x[1] 0.99 0.99 -1.31 -0.940 0.33 1.00 1.7 2.9 3.2 4000
#> [2] x[2] 2.01 1.00 -0.34 0.080 1.32 2.02 2.7 4.0 4.3 4000
#> [3] x[3] 0.99 0.99 -1.32 -0.999 0.33 1.01 1.6 3.0 3.4 4000
#> [4] x[4] 2.00 0.99 -0.27 0.057 1.31 1.99 2.7 3.9 4.3 4000
#> [5] x[5] 1.00 0.99 -1.22 -0.907 0.32 1.00 1.7 3.0 3.3 4000
#> [6] x[6] 1.96 1.01 -0.39 -0.036 1.29 1.96 2.6 4.0 4.2 4000
#> [7] x[7] 0.99 0.98 -1.27 -0.915 0.32 0.98 1.7 2.9 3.3 4000
#> [8] x[8] 2.00 0.99 -0.30 0.087 1.34 2.00 2.7 4.0 4.3 4000
#> [9] x[9] 1.00 0.99 -1.31 -0.961 0.34 1.01 1.7 3.0 3.3 4000
#> [10] x[10] 2.02 0.99 -0.35 0.073 1.38 2.03 2.7 3.9 4.3 4000
cumsum(x)
#> mean sd 1% 2.5% 25% 50% 75% 97.5% 99% sims
#> [1] -0.00623 0.99 -2.3 -1.9 -0.67 -0.00270 0.66 1.9 2.2 4000
#> [2] 0.00309 1.40 -3.1 -2.7 -0.95 -0.00017 0.95 2.7 3.3 4000
#> [3] -0.00256 1.72 -3.9 -3.3 -1.15 0.00837 1.13 3.5 4.0 4000
#> [4] -0.00112 2.00 -4.7 -3.9 -1.35 -0.00421 1.36 4.0 4.6 4000
#> [5] 0.00021 2.23 -5.3 -4.4 -1.49 0.04072 1.48 4.4 5.4 4000
#> [6] -0.04317 2.45 -5.7 -4.8 -1.69 -0.03457 1.60 4.9 5.8 4000
#> [7] -0.04881 2.65 -6.1 -5.2 -1.84 -0.11163 1.68 5.3 6.0 4000
#> [8] -0.04527 2.82 -6.6 -5.6 -1.89 -0.11491 1.78 5.6 6.5 4000
#> [9] -0.04378 3.00 -7.0 -5.9 -2.06 -0.07752 1.93 5.9 6.9 4000
#> [10] -0.01929 3.17 -7.4 -6.1 -2.18 -0.03914 2.07 6.2 7.6 4000
cumprod(exp(x))
#> mean sd 1% 2.5% 25% 50% 75% 97.5% 99% sims
#> [1] 1.6 2.1 0.09906 0.1437 0.51 1.00 1.9 7 9.5 4000
#> [2] 2.8 7.6 0.04464 0.0676 0.39 1.00 2.6 15 28.2 4000
#> [3] 4.6 16.9 0.02085 0.0364 0.32 1.01 3.1 34 56.4 4000
#> [4] 7.6 47.0 0.00866 0.0195 0.26 1.00 3.9 52 102.6 4000
#> [5] 14.7 181.2 0.00525 0.0126 0.23 1.04 4.4 84 226.3 4000
#> [6] 18.2 140.9 0.00343 0.0082 0.18 0.97 4.9 131 322.0 4000
#> [7] 28.6 232.1 0.00225 0.0055 0.16 0.89 5.4 192 415.7 4000
#> [8] 41.6 358.6 0.00134 0.0035 0.15 0.89 5.9 278 680.2 4000
#> [9] 74.9 1115.9 0.00089 0.0027 0.13 0.93 6.9 348 1011.5 4000
#> [10] 221.5 7566.0 0.00059 0.0023 0.11 0.96 7.9 507 2073.7 4000