Learn R Programming

psborrow2 (version 0.0.4.0)

covariance_matrix: Create Covariance Matrix

Description

Create Covariance Matrix

Usage

covariance_matrix(diag, upper_tri)

Value

A symmetric matrix with diag values on the main diagonal and upper_tri values in the lower and upper triangles.

Arguments

diag

Diagonal entries of the covariance matrix

upper_tri

Upper triangle entries of the matrix, specified column wise.

Examples

Run this code
m1 <- covariance_matrix(c(1, 1, 1, 1), c(.8, .3, .8, 0, 0, 0))
m1
mvtnorm::rmvnorm(5, mean = c(0, 0, 0, 0), sigma = m1)

# No correlation
covariance_matrix(c(1, 2, 3))

Run the code above in your browser using DataLab