Skip to contents

Creates a comparison table (via gtsummary) that • summarises variables by a grouping factor, • optionally adjusts continuous outcomes for covariates (ANCOVA), • adds p-values, effect sizes, and pair-wise contrasts, • automatically drops constant variables, • can suppress the "Unknown" row or add an overall N column, and • can return an overall-only summary when requested or when no valid group exists.

Usage

MakeComparisonTable(
  DataFrame,
  CompVariable = NULL,
  Variables,
  Covariates = NULL,
  ValueDigits = 2,
  pDigits = 3,
  AddEffectSize = FALSE,
  EffectSizeDigits = 2,
  AddPairwise = FALSE,
  PairwiseMethod = "bonferroni",
  Parametric = TRUE,
  ParametricDisplay = NULL,
  IncludeOverallN = FALSE,
  IncludeMissing = FALSE,
  suppress_warnings = FALSE,
  Referent = NULL,
  IncludeOverallStats = FALSE,
  ShowPositiveBinaryOnLabel = TRUE
)

Arguments

DataFrame

Data frame with the raw data.

CompVariable

Grouping / comparison variable (character scalar). Optional if IncludeOverallStats = TRUE.

Variables

Character vector of columns to compare.

Covariates

Optional covariates (default NULL).

ValueDigits

Digits in summary stats (default 2).

pDigits

Digits in p-values (default 3).

AddEffectSize

Logical; add effect sizes? (default FALSE).

EffectSizeDigits

Digits in effect sizes (default 2).

AddPairwise

Logical; add pair-wise contrasts? (default FALSE).

PairwiseMethod

P-adjustment method (default "bonferroni").

Parametric

TRUE = parametric tests, FALSE = non-parametric tests (default TRUE).

ParametricDisplay

TRUE = show mean/SD, FALSE = show median/IQR (default matches Parametric).

IncludeOverallN

Logical; add overall N? (default FALSE).

IncludeMissing

Logical; include "Unknown" row? (default FALSE).

suppress_warnings

Suppress gtsummary warnings? (default FALSE).

Referent

Optional reference level for contrasts.

IncludeOverallStats

Logical; if TRUE (default FALSE) or if CompVariable is not present in DataFrame, return overall-only stats.

ShowPositiveBinaryOnLabel

Logical; if TRUE (default) show only the "positive" level (TRUE/1/YES/Yes) of binary categorical/factor/logical variables on the label row.

Value

A gtsummary::tbl_summary object.