data2cor | R Documentation |
Get correlation matrix with Pearson or Spearman correlations
data2cor(
cdata,
exclude = "^ID$|_SE$|_SEM$|_SD$",
type = "spearman",
varfilter = FALSE
)
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. |
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.
A list with M, the correlation matrix, and
N, the number of observations matrix, and
P, the p-values matrix. See rcorr
.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.