Learn R Programming

mvtnorm (version 1.3-1)

ltMatrices: Multiple Lower Triangular or Symmetric Matrices

Description

A class representing multiple lower triangular or symmetric matrices and some methods.

Usage

ltMatrices(object, diag = FALSE, byrow = FALSE, names = TRUE)
syMatrices(object, diag = FALSE, byrow = FALSE, names = TRUE)
# S3 method for ltMatrices
as.array(x, symmetric = FALSE, ...)
# S3 method for syMatrices
as.array(x, ...)
# S3 method for ltMatrices
diagonals(x, ...)
# S3 method for syMatrices
diagonals(x, ...)
# S3 method for matrix
diagonals(x, ...)
# S3 method for integer
diagonals(x, ...)
diagonals(x) <- value
# S3 method for ltMatrices
diagonals(x) <- value
# S3 method for syMatrices
diagonals(x) <- value
# S3 method for ltMatrices
solve(a, b, transpose = FALSE, ...)
# S3 method for syMatrices
chol(x, ...)
# S3 method for chol
aperm(a, perm, ...)
# S3 method for invchol
aperm(a, perm, ...)
# S3 method for ltMatrices
aperm(a, perm, ...)
# S3 method for syMatrices
aperm(a, perm, ...)
deperma(chol = solve(invchol), permuted_chol = solve(permuted_invchol), 
        invchol, permuted_invchol, perm, score_schol)
# S3 method for ltMatrices
Mult(x, y, transpose = FALSE, ...)
# S3 method for syMatrices
Mult(x, y, ...)
Tcrossprod(x, diag_only = FALSE)
Crossprod(x, diag_only = FALSE)
logdet(x)
Lower_tri(x, diag = FALSE, byrow = attr(x, "byrow"))
is.ltMatrices(x)
is.syMatrices(x)
as.ltMatrices(x)
# S3 method for ltMatrices
as.ltMatrices(x)
# S3 method for syMatrices
as.ltMatrices(x)
as.syMatrices(x)
is.chol(x)
is.invchol(x)
as.chol(x)
as.invchol(x)
chol2cov(x)
invchol2chol(x)
chol2invchol(x)
invchol2cov(x)
invchol2pre(x)
chol2pre(x)
Dchol(x, D = 1 / sqrt(Tcrossprod(x, diag_only = TRUE)))
invcholD(x, D = sqrt(Tcrossprod(solve(x), diag_only = TRUE)))
chol2cor(x)
invchol2cor(x)
chol2pc(x)
invchol2pc(x)
vectrick(C, S, A, transpose = c(TRUE, TRUE))
standardize(chol, invchol)
destandardize(chol = solve(invchol), invchol, score_schol)
as.ltMatrices(x)

Value

The constructor ltMatrices returns objects of class ltMatrices

with corresponding methods. The constructor syMatrices returns objects of class syMatrices with a reduced set of methods.

Arguments

object

a matrix representing the lower triagular elements of \(N\) lower triangular matrix, each of dimension \(J \times J\). Dimensions of object depend on diag: With diagonal elements, object is a \(J(J+1)/2 \times N\) matrix, otherwise, the number of rows is \(J(J - 1) / 2\).

diag

logical, object contains diagonal elements if TRUE, otherwise unit diagonal elements are assumed.

byrow

logical, object represents matrices in row-major order if TRUE or, otherwise, in column-major order.

names

logical or character vector of length \(J\).

symmetric

logical, object is interpreted as a symmetric matrix if TRUE.

diag_only

logical, compute diagonal elements of crossproduct only if TRUE.

x,chol,invchol,permuted_chol,permuted_invchol

object of class ltMatrices or syMatrices (for chol).

value

a matrix of diagonal elements to be assigned (of dimension \(J \times N\)).

a

object of class ltMatrices.

perm

a permutation of the covariance matrix corresponding to a.

D

a matrix (of dimension \(J \times N\)) of diagonal elements to be multiplied with.

y

matrix with \(J\) rows.

b

matrix with \(J\) rows.

C

an object of class ltMatrices.

S

an object of class ltMatrices or a matrix with \(J^2\) rows representing multiple \(J x J\) matrices (columns of vec operators).

A

an object of class ltMatrices.

transpose

a logical of length two indicating if A or B shall be transposed in vectrick. For solve, this argument being true computes solve(t(a), b) (in absence of a t() method for ltMatrices objects).

score_schol

score matrix for a standardized chol object.

...

additional arguments, currently ignored.

Details

ltMatrices interprets a matrix as lower triangular elements of multiple lower triangular matrices. The corresponding class can be used to store such matrices efficiently. Matrix multiplications, solutions to linear systems, explicite inverses, and crossproducts can be computed based on such objects. Details can be found in the lmvnorm_src package vignette.

syMatrices only store the lower triangular parts of multiple symmetric matrices.

See Also

vignette("lmvnorm_src", package = "mvtnorm")

Examples

Run this code

  J <- 4L
  N <- 2L
  dm <- paste0("d", 1:J)
  xm <- paste0("x", 1:N)
  (C <- ltMatrices(matrix(runif(N * J * (J + 1) / 2), 
                          ncol = N, dimnames = list(NULL, xm)), 
                   diag = TRUE, names = dm))

  ## dimensions and names
  dim(C)
  dimnames(C)
  names(C)

  ## subset
  C[,2:3]

  ## multiplication
  y <- matrix(runif(N * J), nrow = J)
  Mult(C, y)

  ## solve
  solve(C)
  solve(C, y)

  ## tcrossprod
  Tcrossprod(C)

  ## convert to matrix
  as.array(solve(C[1,]))[,,1]

Run the code above in your browser using DataLab