View source: R/random_correlation_matrix.R
group_cor_mat | R Documentation |
Creates a symmetric correlation matrix with user-defined structure, rank and groupings.
group_cor_mat(
n = c(5, 5),
within.cor = 0.5,
between.cor = 0.2,
range = NULL,
rank = 4,
skew = 0,
pos.def = FALSE,
small.positive = NULL,
return.groups = FALSE
)
n |
A vector defining the size of each group. |
within.cor |
A vector defining the baseline correlation within each group.
If only one value is supplied, all groups will be assigned the same correlation. |
between.cor |
A scalar defining the baseline correlation between groups. |
range |
A scalar defining the range of correlations around the baseline. By default,
|
rank |
A scalar defining the rank of the correlation matrix. |
skew |
A scalar defining the skewness imposed on the correlations.
Note: |
pos.def |
When |
small.positive |
Argument passed to |
return.groups |
When |
A symmetric correlation matrix with defined rank and groupings.
When pos.def = TRUE
, the correlation matrix is guaranteed to be positive (semi)-definite.
When return.groups = TRUE
, a list is returned with additional entries containing the group members.
# Simulate and visualise a correlation matrix with 2 groups containing 5 and 10 members,
# correlations of 0.4 within groups and 0 between groups and rank equal to 4
cor_ls <- group_cor_mat(
n = c(5, 10),
within.cor = 0.4,
between.cor = 0,
rank = 4,
return.groups = TRUE
)
plot_matrix(
mat = cor_ls$cor.mat,
group.df = cor_ls$group.df,
order = TRUE
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.