correlationMatrix: Pretty correlation matrix

Description Usage Arguments Details Value Source Examples

View source: R/descriptives.R

Description

Calculates a correlation matrix for a dataset and display variables, as well as P-values in asteriks notation nicely. The function also writes the table into a LaTeX file if desired.

Usage

1
2
3
correlationMatrix(x, y = NULL, method = c("pearson", "spearman"),
  removeTriangle = c("upper", "lower", "none"), diagonale = FALSE,
  digits = 3, filename = NULL)

Arguments

x

A numeric matrix for which to compute the correlation matrix.

y

Optional second matrix. If omitted or NULL, it is replaced by x.

method

Method, i.e. Pearson's r or Spearman's rho rank correlation coefficients.

removeTriangle

Parameter indicating whether to remove a duplicated triangle of the matrix. Defaul is the upper triangle that is removed.

diagonale

If FALSE (default), the diagonale is omitted. If TRUE, it is included as 1 along with significance stars.

digits

Number of digits to be printed (default: 3).

filename

Path to which a LaTeX copy is exported (default is NULL). If NULL, no file is generated.

Details

To embed this correlation table inside LaTeX, requires a specific format as follows:

  1. Insert the library SIunitx inside the preamble of your LaTeX document.

  2. At the same location, define the following macro \newcommand{\sym[1]\rlap{$^{#1}$}}

  3. Also in the preamble, change the sisetup \sisetup{input-symbols={()*}}

  4. Finally, choose S as your column alignment.

Details: http://tex.stackexchange.com/questions/47418/siunitx-specifying-custom-command-as-input-symbol; also refer to the example in the README.

Value

Correlation matrix with pretty output.

Source

Idea: http://www.sthda.com/english/wiki/elegant-correlation-table-using-xtable-r-package

Examples

1
2
3
4
5
6
data(USArrests)
correlationMatrix(USArrests)

# alternatively, with table exported into a LaTeX file
correlationMatrix(USArrests, filename = "table_cor.tex")
unlink("table_cor.tex")

sfeuerriegel/ResearchGroupTools documentation built on May 29, 2019, 8:01 p.m.