data2cor: Get correlation matrix and observations used

View source: R/data2cor.R

data2corR Documentation

Get correlation matrix and observations used

Description

Get correlation matrix with Pearson or Spearman correlations

Usage

data2cor(
  cdata,
  exclude = "^ID$|_SE$|_SEM$|_SD$",
  type = "spearman",
  varfilter = FALSE
)

Arguments

cdata

A 'data.table'.

exclude

Optional, name pattern of column to exclude, e.g. columns containing IDs or other data where relationships are not calculated. The default excludes columns named "ID" and columns ending with "_SE", "_SEM", and "_SD".

type

Either "pearson" or "spearman", defaults to "spearman".

varfilter

Whether to remove zero-variance data before calculations.

Details

This implementation first converts data.table into a cleaned matrix, discarding any non-numeric data and excluding certain columns for correlation calculations (such as "ID" and SE/SD columns by default). Columns to be exluded can be specified through name patterns. Pearson or Spearman correlation is calculated using rcorr; the method can be specified depending on the data input. Because the original use case includes ordinal data as well as data that might violate normality assumptions, the more conservative Spearman rank correlation is set as the default (interval vs ordinal & ordinal vs ordinal data). In the future it might be possible to extend the implementation to include nominal variables by using other association statistics such as Cramer's V, eta, lambda (something like data2association) so the result will be a heterogeneous correlation/association matrix.

Value

A list with M, the correlation matrix, and N, the number of observations matrix, and P, the p-values matrix. See rcorr.


avucoh/DIVE documentation built on Aug. 29, 2023, 6:02 p.m.