Multiplies two random matrices, if they are conformable. If one argument is a vector, it will be coerced to either a row or column matrix to make the two arguments conformable. If both are vectors it will return the inner product.

`%*%.rv`(x, y)

x %**% y

Arguments

x, y

numeric or complex matrices or vectors.

Value

The (distribution of the) matrix product. Use drop to get rid of dimensions which have only one level.

Details

Optimized internally for the case of random matrix multiplied by a constant column vector.

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

See also

Examples


x <- 1:4
(z <- x %*% x)    # scalar ("inner") product (1 x 1 matrix)
#>      [,1]
#> [1,]   30
drop(z)             # as scalar
#> [1] 30

y <- diag(x)
z <- matrix(1:12, ncol = 3, nrow = 4)
y %*% z
#>      [,1] [,2] [,3]
#> [1,]    1    5    9
#> [2,]    4   12   20
#> [3,]    9   21   33
#> [4,]   16   32   48
y %*% x
#>      [,1]
#> [1,]    1
#> [2,]    4
#> [3,]    9
#> [4,]   16
x %*% z
#>      [,1] [,2] [,3]
#> [1,]   30   70  110