rand_cor_mat {FieldSimR}R Documentation

Simulate a random correlation matrix

Description

Creates a symmetric n x n correlation matrix with user-defined minimum and maximum correlations.

Usage

rand_cor_mat(
  n = 2,
  min.cor = -1,
  max.cor = 1,
  pos.def = FALSE,
  small.positive = NULL
)

Arguments

n

A scalar defining the dimensions of the correlation matrix.

min.cor

A scalar defining the minimum correlation.

max.cor

A scalar defining the maximum correlation.
Note: -1 < min.cor < max.cor < 1.

pos.def

When TRUE (default is FALSE), the function bend of the R package 'mbend' is used with default arguments to bend a non-positive-definite matrix to a positive (semi)-definite matrix.

small.positive

Argument passed to bend when pos.def = TRUE (default is 0.0001). Eigenvalues smaller than small.positive are replaced with this value.
Note: 0 < small.positive < 0.1.

Value

A symmetric n x n correlation matrix. When pos.def = TRUE, the correlation matrix is guaranteed to be positive (semi)-definite.

Examples

# Simulate a random correlation matrix with 10 columns and rows.

corA <- rand_cor_mat(
  n = 10,
  min.cor = -0.2,
  max.cor = 0.8,
  pos.def = TRUE,
  small.positive = 1e-4
)


[Package FieldSimR version 1.3.0 Index]