Skip to main content

Table of a correlation analysis

Description

One function, three layouts, all built from the output of cor_compute() with the same colour scale as plot_cor_heatmap():

  • “matrix”: lower triangle of a matrix analysis, as in the heatmap;

  • “wide”: one row per x, one column per y (cross analysis);

  • “long”: one row per pair, with n, coefficient, confidence interval, raw p and (if requested) adjusted p; rows grouped by the family of the adjustment.

Usage

tbl_cor(
  x,
  layout = c("auto", "matrix", "wide", "long"),
  labels = NULL,
  digits = 2,
  use_adj = TRUE,
  order = c("original", "hclust"),
  alpha = 0.05,
  sort_by = c("none", "abs"),
  palette = COR_PAL,
  show_note = TRUE,
  title = NULL,
  subtitle = NULL
)

Arguments

x output of cor_compute()
layout “auto”, “matrix”, “wide” or “long”
labels named vector variable -> label (default: the labels given to cor_compute())
digits decimals of the coefficients
use_adj stars on adjusted (TRUE) or raw p-values (“matrix” and “wide”)
order “matrix” only: “original” or “hclust” (same ordering as the heatmap)
alpha “long” only: rows with a p-value (adjusted if requested) below alpha in bold
sort_by “long” only: “none” or “abs” (decreasing |coefficient| within groups)
palette colours (named low / high); NULL = no colour
show_note add the reading lines of binary variables
title, subtitle override the automatic texts

Details

layout = “auto” gives “matrix” for a matrix analysis and “wide” for a cross analysis. The subtitle and the source notes state the method, the adjustment for covariates, N, the engine, the status of the p-values, the formula of the coefficient and the reading of binary variables.

Value

a gt_tbl

Examples

library("corrkit")

d   <- simulate_cor_data(150)
lab <- attr(d, "labels")
cm <- cor_compute(d, c("CRP", "IL6", "BDNF", "NfL", "BIN_CRP"), labels = lab)
tbl_cor(cm)                    # matrix
Correlation matrix
Spearman correlation, unadjusted | pairwise complete N = 142–146 | Computed with psych::corr.test() {psych}; p adjustment: none (raw p-values)
CRP IL-6 BDNF NfL CRP high [0/1]
CRP 1
IL-6 0.41*** 1
BDNF -0.14 -0.23** 1
NfL 0.12 0.08 -0.05 1
CRP high [0/1]1 0.87*** 0.30*** -0.10 0.12 1
1 Binary variable [0/1], coded 0/1 (upper level = 1).
Raw p (no multiple-testing adjustment): * < 0.05, ** < 0.01, *** < 0.001; no star = p ≥ 0.05.
Continuous: r_s = cov(rank_x, rank_y) / (SD(rank_x) × SD(rank_y)); t-test, n − 2 df.
Binary [0/1]: r_s = r_rb × √(3pq), r_rb = 2 AUC − 1 (rank-biserial, ≡ Mann-Whitney test), p, q = group proportions; |r_s| ≤ 0.87, not comparable with continuous pairs.
Confidence intervals: tbl_cor(layout = "long").
Notation: Makowski D, Ben-Shachar MS, Patil I, Lüdecke D (2020), J Open Source Softw 5(51):2306, doi:10.21105/joss.02306.
tbl_cor(cm, layout = "long")
Spearman correlations
Spearman correlation, unadjusted | pairwise complete N = 142–146 | Computed with psych::corr.test() {psych}; p adjustment: none (raw p-values)
Variable 1 Variable 2 Pair n rₛ 95% CI p (raw)
CRP IL-6 cont × cont 142 0.41 [0.26, 0.54] < 0.001 ***
CRP BDNF cont × cont 142 -0.14 [-0.30, 0.03] 0.099
CRP NfL cont × cont 142 0.12 [-0.05, 0.29] 0.145
CRP CRP high [0/1] cont × bin 146 0.87 [0.82, 0.90] < 0.001 ***
IL-6 BDNF cont × cont 142 -0.23 [-0.38, -0.06] 0.007 **
IL-6 NfL cont × cont 142 0.08 [-0.09, 0.25] 0.344
IL-6 CRP high [0/1] cont × bin 142 0.30 [0.14, 0.45] < 0.001 ***
BDNF NfL cont × cont 142 -0.05 [-0.21, 0.12] 0.581
BDNF CRP high [0/1] cont × bin 142 -0.10 [-0.26, 0.07] 0.239
NfL CRP high [0/1] cont × bin 142 0.12 [-0.05, 0.29] 0.145
Pair: cont = continuous, bin = binary[0/1]. Bold = p < 0.05.
Raw p (no multiple-testing adjustment): * < 0.05, ** < 0.01, *** < 0.001; no star = p ≥ 0.05.
Continuous: r_s = cov(rank_x, rank_y) / (SD(rank_x) × SD(rank_y)); t-test, n − 2 df.
95% CI: Fisher z transformation, SE = √(1.06 / (n − 3)) (Fieller et al. 1957); computed with correlation::cor_to_ci() {correlation}.
Binary [0/1]: r_s = r_rb × √(3pq), r_rb = 2 AUC − 1 (rank-biserial, ≡ Mann-Whitney test), p, q = group proportions; |r_s| ≤ 0.87, not comparable with continuous pairs.
Notation: Makowski D, Ben-Shachar MS, Patil I, Lüdecke D (2020), J Open Source Softw 5(51):2306, doi:10.21105/joss.02306.
cc <- cor_compute(d, c("CRP", "IL6", "BIN_CRP"), c("depression", "fatigue"),
                  covariates = "age", labels = lab)
tbl_cor(cc)                    # wide
Spearman correlations
Spearman correlation, partial, adjusted for Age | N = 142–143 | Computed with ppcor::pcor.test() {ppcor}; p adjustment: none (raw p-values)
Depression score Fatigue score
Continuous
CRP 0.22** 0.07
IL-6 0.35*** 0.38***
Binary [0/1]
CRP high [0/1]1 0.18* 0.07
1 [0/1] binary: r_s ≈ Mann-Whitney (rank difference between groups); |r_s| ≤ √(3pq) ≤ 0.87, not comparable with continuous variables
Cells: r_s and stars; colour = same scale as the heatmap (blue < 0 < red). Confidence intervals: tbl_cor(layout = "long").
Raw p (no multiple-testing adjustment): * < 0.05, ** < 0.01, *** < 0.001; no star = p ≥ 0.05.
Continuous: r_s = cov(rank_x, rank_y) / (SD(rank_x) × SD(rank_y)); partial: r_s,xy.z = r(e_x.z, e_y.z), residuals of the ranks on the k = 1 covariate terms z; t-test, n − 2 − k df.
Binary [0/1]: r_s = r_rb × √(3pq), r_rb = 2 AUC − 1 (rank-biserial, ≡ Mann-Whitney test), p, q = group proportions; |r_s| ≤ 0.87, not comparable with continuous pairs.
Notation: Makowski D, Ben-Shachar MS, Patil I, Lüdecke D (2020), J Open Source Softw 5(51):2306, doi:10.21105/joss.02306.
Back to top