decomp_cov: Decompose covariance matrix

Description Usage Arguments Details Value Author(s) Examples

View source: R/decomp_cov.R

Description

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

Usage

1
2
3
decomp_cov(v, method = "eigen")

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

Details

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

Value

Returns an N \times N matrix.

Author(s)

Joshua French

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# 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
all.equal(v, tcrossprod(d1))
all.equal(v, tcrossprod(d2), check.attributes = FALSE)
all.equal(v, tcrossprod(d3), check.attributes = FALSE)

gear documentation built on April 14, 2020, 5:12 p.m.

Related to decomp_cov in gear...