Description Usage Arguments Details Value Author(s) See Also Examples
Factorizing matrices with various method.
1 |
x |
|
method |
|
... |
additional arguments passed to the underlying main functions; see the source code for 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
.
The factor, that is, the factorized matrix
. This is a
matrix R such that such that R^T R equals x
.
Marius Hofert
rstudent()
where factorize()
is used.
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))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.