Learn R Programming

multiSA (version 0.1.0)

conv_Sigma: Calculate covariance matrix

Description

Uses Cholesky factorization to generate a covariance matrix (or any symmetric positive definite matrix).

Usage

conv_Sigma(sigma, lower_diag)

Value

Numeric

Arguments

sigma

Numeric vector of marginal standard deviations (all greater than zeros)

lower_diag

Numeric vector to populate the lower triangle of the correlation matrix. All real numbers. Length sum(1:(length(sigma) - 1))

Examples

Run this code
set.seed(23)
n <- 5
sigma <- runif(n, 0, 2)
lower_diag <- runif(sum(1:(n-1)), -10, 10)
Sigma <- conv_Sigma(sigma, lower_diag)
Sigma/t(Sigma) # Is symmetric matrix? All ones
cov2cor(Sigma)

Run the code above in your browser using DataLab