factorize: Matrix Factorization

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/auxiliaries.R

Description

Factorizing matrices with various method.

Usage

1
factorize(x, method = c("chol", "chol.pivot", "eigen", "svd"), ...)

Arguments

x

matrix.

method

character string specifying the factorization method. Available are:

"chol"

Cholesky decomposition of a positive definite matrix based on chol().

"chol.pivot"

Cholesky decomposition of a positive semidefinite matrix based on chol(, pivot = TRUE); see ?chol for more details.

"eigen"

factor from an eigendecomposition.

"svd"

factor from a singular-value decomposition.

...

additional arguments passed to the underlying main functions; see the source code for details.

Details

When the factor R is multiplied from the right to an (n, d)-matrix of independent standard normals, one obtains a sample from a multivariate normal with zero mean vector and covariance matrix x.

Value

The factor, that is, the factorized matrix. This is a matrix R such that such that R^T R equals x.

Author(s)

Marius Hofert

See Also

rstudent() where factorize() is used.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
## Generate a random correlation matrix in dimension 5
d <- 5
set.seed(271)
A <- matrix(runif(d * d), ncol = d)
P <- cov2cor(A %*% t(A))
## Factorizations
A.chol       <- factorize(P) # Cholesky factor
A.chol.pivot <- factorize(P, method = "chol.pivot") # with pivoting
A.eigen      <- factorize(P, method = "eigen") # factor from eigendecomposition
A.svd        <- factorize(P, method = "svd") # from singular-value decomposition
## Check
P.chol       <- t(A.chol) %*% A.chol
P.chol.pivot <- t(A.chol.pivot) %*% A.chol.pivot
P.eigen      <- t(A.eigen) %*% A.eigen
P.svd        <- t(A.svd) %*% A.svd
stopifnot(all.equal(P.chol, P), all.equal(P.chol.pivot, P),
          all.equal(P.eigen, P), all.equal(P.svd, P))

student documentation built on May 2, 2019, 6:48 p.m.