create_cor_mat: Create a correlation matrix, given a vector of correlations

Description Usage Arguments Details Value See Also Examples

View source: R/create_covcor.R

Description

Create a correlation matrix, given a vector of correlations. If no vector of correlations, a random correlation matrix 2 x 2 will be created.

Usage

1
create_cor_mat(cors = 2L, tol = .Machine$double.eps^0.5)

Arguments

cors

A vector of correlations of a the nb of variables.

tol

Tolerance for the output matrix. Change only if you have a good reason.

Details

Create a positive-definite matrix which represents the correlations given by the user or, when cors is a count, a random correlation matrix of size cors x cors.

Value

Correlation matrix with the correlations cors, or, if cors is a count, a random correlation matrix of cors variables.

See Also

calc_nvars sim_cor_mat

Examples

1
2
3
4
5
6
7
8
9
nvars <- 4  # nb of variables
npairs <- choose(nvars, 2)  # nb of pairs that can be made with nvars
# this sequence gives a positive definite matrix
cors <- seq(from = 0.1, to = 0.9, length.out = npairs)
Rho <- create_cor_mat(cors)
stopifnot(all.equal(dim(Rho), c(nvars, nvars)))
# create matrix of random correlations for nvars variables
Rho <- create_cor_mat(nvars)
stopifnot(all.equal(dim(Rho), c(nvars, nvars)))

FrankLef/eflStats documentation built on Dec. 17, 2021, 8:30 p.m.