Learn R Programming

brainGraph (version 1.0.0)

corr.matrix: Calculate correlation matrix and threshold

Description

This function does a column-by-column correlation of a given data frame, and will threshold the matrix based on a given density; e.g. 0.1 if you want to keep only the 10% strongest correlations.

Usage

corr.matrix(dat, thresh = NULL, density = 0.1, exclusions = NULL, ...)

Arguments

dat
Data table of the data to correlate
thresh
Numeric; absolute correlation value to threshold by
density
Numeric indicating the resultant network density; keeps the top X% of correlations
exclusions
Numeric vector of indices (columns) to exclude (optional)
...
Other arguments to be passed to rcorr

Value

A list with the following components:
R
Numeric matrix of correlation coefficients.
P
Numeric matrix of p-values.
r.thresh
Binary matrix indicating correlations that are above a certain threshold.
threshold
Numeric; the threshold value used.

Details

If you wish to exclude regions from your analysis, you can give the indices of their columns. This function is essentially a wrapper for rcorr, with some added functionality to work with this type of data more easily. By default, the Pearson correlation coefficients are calculated, but can return Spearman by passing an additional argument.

See Also

rcorr

Examples

Run this code
## Not run: ------------------------------------
# corrs <- lapply(groups, function(x) lapply(densities, function(y)
#   corr.matrix(resids.all[x], density=y)))
## ---------------------------------------------

Run the code above in your browser using DataLab