Matrix multiplication of random variables.

x %**% y

x | (multiple options) The object to be postmultiplied by If a vector is used, it is treated as a |
---|---|

y | (multiple options) The object to be premultiplied by If a vector is used, it is treated as a |

An `rvar`

representing the matrix product of `x`

and `y`

.

If `x`

or `y`

are vectors, they are converted into matrices prior to multiplication, with `x`

converted to a row vector and `y`

to a column vector. Numerics and logicals can be multiplied
by `rvar`

s and are broadcasted across all draws of the `rvar`

argument. Tensor multiplication
is used to efficiently multiply matrices across draws, so if either `x`

or `y`

is an `rvar`

,
`x %**% y`

will be much faster than `rdo(x %*% y)`

.

Because `rvar`

is an S3 class and S3 classes cannot properly override `%*%`

, `rvar`

s use
`%**%`

for matrix multiplication.

# d has mu (mean vector of length 3) and Sigma (3x3 covariance matrix) d <- as_draws_rvars(example_draws("multi_normal")) d$Sigma#> rvar<100,4>[3,3] mean ± sd: #> [,1] [,2] [,3] #> [1,] 1.28 ± 0.17 0.53 ± 0.20 -0.40 ± 0.28 #> [2,] 0.53 ± 0.20 3.67 ± 0.45 -2.10 ± 0.48 #> [3,] -0.40 ± 0.28 -2.10 ± 0.48 8.12 ± 0.95#> rvar<100,4>[3,3] mean ± sd: #> [,1] [,2] [,3] #> [1,] 1.28 ± 0.17 1.05 ± 0.40 -1.21 ± 0.85 #> [2,] 0.53 ± 0.20 7.33 ± 0.89 -6.30 ± 1.44 #> [3,] -0.40 ± 0.28 -4.20 ± 0.96 24.35 ± 2.84# Decompose Sigma into R s.t. R'R = Sigma ... R <- chol(d$Sigma) # ... and recreate Sigma using matrix multiplication t(R) %**% R#> rvar<100,4>[3,3] mean ± sd: #> [,1] [,2] [,3] #> [1,] 1.28 ± 0.17 0.53 ± 0.20 -0.40 ± 0.28 #> [2,] 0.53 ± 0.20 3.67 ± 0.45 -2.10 ± 0.48 #> [3,] -0.40 ± 0.28 -2.10 ± 0.48 8.12 ± 0.95