chol2cov: Cholesky correlation matrix and standard deviations to...

Description Usage Arguments Value Examples

View source: R/stats.R

Description

Cholesky correlation matrix and standard deviations to covariance matrix

Usage

1
chol2cov(sigma, cm, tcross = FALSE)

Arguments

sigma

sigma vector

cm

cholesky factor correlation matrix

tcross

set to TRUE to use tcrossprod instead of crossprod. That is, if cm is flipped as in STAN.

Value

matrix, covariances

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# correlation matrix
m <- matrix(c(1,-0.15,0.67,-0.15,1,.2,0.67,.2,1), ncol=3)

# standard deviations on the diagonal
sigma <- c(.5, 1, 1.5)

# R formatted cholesky factor
cm <- chol(m)
chol2cov(sigma, cm)

# STAN formatted cholesky factor
cm <- stan_chol(m)
chol2cov(sigma, cm, TRUE)

iamamutt/mejr documentation built on May 18, 2019, 1:27 a.m.