Skip to contents

Generates standard epidemiological Table 1 descriptive statistics and Table 1b completeness audit.

Usage

generate_table1(
  data,
  strata_col = "outcome_flag",
  continuous_vars = NULL,
  categorical_vars = NULL,
  table_name = NULL,
  strata_labels = NULL,
  compute_smd = TRUE,
  compute_pvalues = TRUE,
  decimal_places = 1,
  groups = NULL
)

Arguments

data

A data.frame or active DuckDB DBI connection.

strata_col

Column name defining stratification (default "outcome_flag").

continuous_vars

Character vector of continuous column names.

categorical_vars

Character vector of categorical column names.

table_name

Character string of table name if data is a DuckDB connection.

strata_labels

Named list mapping strata values to display names.

compute_smd

Logical. Compute Standardized Mean Differences between strata (default TRUE).

compute_pvalues

Logical. Compute p-values between strata (default TRUE).

decimal_places

Decimal places for numeric outputs: one integer for every variable, or a named vector / list c(lab_creatinine = 2, age = 1) per variable. Variables not named use the default entry, else 1. Percentages of a categorical variable follow that variable's setting; the header row uses the default.

groups

Optional named list list("Demographics" = c("age", "female"), ...). Variables are ordered by section, each preceded by a header row (Variable = the title, other cells blank); variables not listed follow under "Other". Unknown names are ignored and a variable listed twice stays in its first section.

Value

A list containing:

  • table1: Formatted Table 1 descriptive statistics.

  • table1b: Table 1b completeness / missingness matrix.