Learn R Programming

gear (version 0.1.5)

decomp.cov: Decompose covariance matrix

Description

decomp.cov decomposes a covariance matrix v. If A = decomp.cov(v), then tcrossprod(A, A) == v.

Usage

decomp.cov(v, method = "eigen")

Arguments

v

An \(n \times n\) covariance matrix.

method

The method used to decompose v. valid options are "chol", "eigen", or "svd".

Value

Returns an \(n \times n\) matrix.

Details

The "chol" method is the fastest, but must unstable. The "eigen" method is slower, but more stable. The "svd" method is the slowest method, but should be the most stable.

Examples

Run this code
# NOT RUN {
# generate data
n = 100
coords = matrix(runif(n*2), nrow = n, ncol = 2)
d = as.matrix(dist(coords))
# create covariance matrix
v = 3*exp(-d/2) + 0.1*diag(n)

# decompose v using the three methods
d1 = decomp.cov(v, "chol")
d2 = decomp.cov(v, "eigen")
d3 = decomp.cov(v, "svd")

# verify accuracy of decompositions
range(v - tcrossprod(d1))
range(v - tcrossprod(d2))
range(v - tcrossprod(d3))
# }

Run the code above in your browser using DataLab