Description Usage Arguments Details Value See Also Examples
View source: R/create_covcor.R
Create a correlation matrix, given a vector of correlations. If no vector of correlations, a random correlation matrix 2 x 2 will be created.
1 | create_cor_mat(cors = 2L, tol = .Machine$double.eps^0.5)
|
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. |
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.
Correlation matrix with the correlations cors, or, if
cors is a count, a random correlation matrix of cors variables.
calc_nvars sim_cor_mat
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)))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.