corrmat_rand: Strength Preserving Correlation Matrix Randomizer

Description Usage Arguments Value Examples

View source: R/corr_rewire.R

Description

This function implements the Masuda, Kojaku & Sano (2018) "Configuration model for correlation matrices preserving the node strength" algorithm for generating correlation matrices that have the same strength distribution as the original matrix.

Usage

1
2
corrmat_rand(org_corr, sampleSize, n, tol = 1e-04, stepSize = 0.001,
  verbose = F)

Arguments

org_corr

A p \times p positive definite covariance (which will be transformed into a correlation matrix) or a correlation matrix

sampleSize

The sample size for a correlation matrix, lower values for more sampling error

n

Number of random correlations matrices to return

tol

Tolerance for configuration model convergence. Default to .0001

stepSize

Step size for configuration model NR solver. Increase to increase convergence speed. Default to .001

verbose

Print convergence information to screen.

Value

A list containing: A p \times p \times n array of rewired correlation matrices and a p \times p matrix of the configuration model.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
org_corr = matrix(0, 20, 20)

org_corr[1:10, 1:10] = .5
org_corr[11:20, 11:20] = .5

noise = t(sapply(as.list(1:100),FUN= function(x){return(rnorm(20,0,1))}))

org_corr = cov2cor(org_corr + cov(noise))

rand_corr = corrmat_rand(org_corr, 10000, 1)[[1]]

org_strength = colSums(org_corr)
rand_strength = colSums(rand_corr)

cor(org_strength, rand_strength)

GatesLab/evalClust documentation built on Nov. 17, 2019, 3:59 a.m.