crossprodV: Matrix cross-product.

View source: R/crossprodV.R

crossprodVR Documentation

Matrix cross-product.

Description

Vectorized matrix cross-products t(X) V Y or t(X) V^{-1} Y.

Usage

crossprodV(X, Y = NULL, V, inverse = FALSE)

Arguments

X

A matrix of size p x q, or an array of size p x q x n.

Y

A matrix of size p x r, or an array of size p x r x n. If missing defaults to Y = X.

V

A matrix of size p x p, or an array of size p x p x n.

inverse

Logical; whether or not the inner product should be calculated with V or V^{-1}.

Value

An array of size q x r x n.

Examples

# problem dimensions
p <- 4
q <- 2
r <- 3
n <- 5
X <- array(rnorm(p*q*n), dim = c(p, q, n)) # vectorized
Y <- array(rnorm(p*r*n), dim = c(p, r, n)) # vectorized
V <- crossprod(matrix(rnorm(p*p), p, p)) # not vectorized (but positive definite)
crossprodV(X = X, V = V) # self cross-product
# cross-product with inverse matrix weight
crossprodV(X = X, V = V, Y = Y, inverse = TRUE)

mniw documentation built on Aug. 22, 2022, 5:05 p.m.