Skip to contents

Formats a tidy data frame of (partial) correlation results into a publication-ready table. Expects pre-computed coefficients as a tidy data frame with one row per predictor x outcome pair.

Column-name arguments accept character strings (quoted names). Defaults match a typical correlation results frame with columns named variable, outcome, r, and p.

Usage

tbl_correlation(
  data,
  predictor = "variable",
  outcome = "outcome",
  r = "r",
  p = "p",
  n = NULL,
  extra_cols = NULL,
  domains = list(),
  fdr = FALSE,
  fdr_within = NULL,
  digits = 3,
  p_digits = 3,
  pivot = FALSE,
  output = c("gt", "html", "latex")
)

Arguments

data

A tidy data frame of correlation results.

predictor

Character string. Name of the predictor variable column. Default "variable".

outcome

Character string. Name of the outcome variable column. Default "outcome".

r

Character string. Name of the correlation coefficient column. Default "r".

p

Character string. Name of the p-value column. Default "p".

n

Character string or NULL. Name of the sample size column. Default NULL (omitted).

extra_cols

Character vector of additional column names to carry through (e.g. "hemisphere", "lobe").

domains

A named list mapping predictor variable names to domain/section labels.

fdr

Logical. Apply BH FDR correction (default FALSE).

fdr_within

Character string or NULL. Column name to group FDR correction within (e.g. "outcome").

digits

Integer. Decimal places for r (default 3).

p_digits

Integer. Decimal places for p-values (default 3).

pivot

Logical. Pivot to wide format with one column per outcome (default FALSE).

output

Character string. One of "gt" (default), "html", or "latex".

Value

A clerk_tbl object with type "correlation".

Examples

tbl_correlation(
  clerk_cor_example,
  domains = list(
    "Metabolic"      = c("hdl", "glucose", "bmi"),
    "Anthropometric" = c("waist", "systolic_bp"),
    "Mental health"  = c("bdi", "panas_neg")
  ),
  fdr    = TRUE,
  output = "gt"
) |> clerk_render(title = "Partial correlations (age + sex controlled)")
#> Warning: invalid factor level, NA generated
Partial correlations (age + sex controlled)
Outcome r p p (FDR)
Metabolic
hdl tmt_time +0.190 0.008 0.032
glucose tmt_time -0.229 0.398 0.398
bmi tmt_time -0.086 0.013 0.042
hdl verbal_fluency +0.078 0.072 0.154
glucose verbal_fluency +0.216 0.003 0.024
bmi verbal_fluency +0.022 0.207 0.255
Anthropometric
waist tmt_time +0.279 0.002 0.024
systolic_bp tmt_time +0.195 0.379 0.398
waist verbal_fluency +0.047 0.185 0.247
systolic_bp verbal_fluency -0.105 0.077 0.154
Mental health
bdi tmt_time +0.096 0.109 0.170
panas_neg tmt_time +0.157 0.006 0.032
bdi verbal_fluency -0.176 0.070 0.154
panas_neg verbal_fluency +0.232 0.117 0.170
NA
life_satisfaction tmt_time +0.247 0.117 0.170
life_satisfaction verbal_fluency +0.201 0.234 0.267