cor.testDT: Perform pairwise correlation tests between matrix columns

View source: R/cor.testDT.R

cor.testDTR Documentation

Perform pairwise correlation tests between matrix columns

Description

Compute pairwise correlation between multiple outcomes. Can reorder the outcomes according to a clustering of the obtained correlations.

Usage

cor.testDT(
  data,
  format,
  col.value = NULL,
  col.group = NULL,
  lower.tri = TRUE,
  upper.tri = FALSE,
  method.cor = "cor.test",
  use.pairwiseNNA = TRUE,
  reorder = "AOE",
  imput.value = 0,
  hclust.method = "complete",
  trace = TRUE,
  plot = TRUE,
  args.plot = list(),
  output = "data.table",
  ...
)

Arguments

data

the dataset.

format

[character] the format of data. Can be "wide" or "long"

col.value

[character vector] columns containing the values to be analyzed. In wide format, all the columns will be used if NULL.

col.group

[character] column defining the groups of observations between which the correlation will be computed.

lower.tri

[logical] should only the lower triangle of the matrix be filled?

upper.tri

[logical] should only the upper triangle of the matrix be filled?

method.cor

[character] the method used to compute the correlation. Must at least have x and y as arguments.

use.pairwiseNNA

[logical]] If FALSE correlation is set to NA if their is one NA among the two outcomes. Otherwise the correlation is computed on pairs without NA.

reorder

[character] argument order of corrMatOrder. If NULL the original order of the variables is kept.

imput.value

[numeric] the value to be used in the clustering algorithm in place of NA. Can be a number or an operator (e.g. median).

hclust.method

[character] argument hclust.method of corrMatOrder.

trace

[logical] should the progression of the computation of the correlation be displayed. logical.

plot

[logical] should the correlation matrix be displayed. logical.

args.plot

[list] arguments to be passed to ggHeatmap to specify how the correlation matrix should be displayed

output

[character] how to output the correlation value. Can be matrix, data.table or plot.

...

additional arguments to be passed to method.cor.

Details

data must be coercible to data.table.

If data="wide" each column correspond to a different outcomes, indicated by argument names.
If data="long" then the first value of names is used to define the outcomes and the seconde is used to define their values.

method.cor can be any method but its first two arguments, named x and y, will be given the values of the outcomes.
If imput.value is an operator then it is applied on the values in the same line or column.
This function uses the function ggHeatmap to display the correlation matrix.

Value

An object determined by the output argument

See Also

ggHeatmap to display the correlation matrix

Examples

M <- matrix(rnorm(1e3),100,10)

## display correlation matrix with color
cor.testDT(M, format = "wide")

## display correlation matrix with color and text
cor.testDT(M, format = "wide",
           args.plot = list(add.text = "correlation", round = 1))

## use spearman instead of pearson
cor.testDT(M, format = "wide", method.cor = function(x,y,...){cor.test(x,y,method = "spearman")},
           args.plot = list(add.text = "correlation", round = 1))


bozenne/butils documentation built on Oct. 14, 2023, 6:19 a.m.