Skip to contents

Generates a summary table for biostatistics and clinical data analysis with automatic normality, effect size, and statistical test calculations. Handles both numeric and categorical variables, performing appropriate descriptive statistics and inferential tests for single-group summaries or two-group comparisons.

Usage

summary_table(
  data,
  group_by = NULL,
  normality_test = "S-W",
  all = FALSE,
  effect_size = FALSE,
  exclude = NULL
)

Arguments

data

Dataframe containing the variables to be summarized.

group_by

Character string indicating the name of the grouping variable for two-group comparisons. Default: NULL.

normality_test

Character string indicating the normality test to use: 'S-W' for Shapiro-Wilk or 'K-S' for Kolmogorov-Smirnov with Lilliefors' correction. Default: 'S-W'.

all

Logical parameter that shows all calculated statistics. Default: FALSE.

effect_size

Logical parameter that includes effect size estimates. Default: FALSE.

exclude

Character vector of variable names to exclude from the summary. Default: NULL.

Value

A gt table object with formatted summary statistics.

Examples

# Simulated clinical data
clinical_df <- clinical_data()

# Overall summary without considering treatment groups
summary_table(clinical_df,
              exclude = c('participant_id', 'visit'))
variable n summary normality
sex 300 Male: 159 (53.0%); Female: 141 (47.0%) NA
treatment 300 Placebo: 153 (51.0%); Treatment: 147 (49.0%) NA
age 300 Median (IQR): 43.50 (20.50) <0.001
weight 300 Median (IQR): 70.70 (21.52) <0.001
biomarker 300 Mean (SD): 48.13 (9.70) 0.772
response 300 Complete: 88 (29.3%); Partial: 70 (23.3%); None: 142 (47.3%) NA
# Grouped summary by treatment group summary_table(clinical_df, group_by = 'treatment', exclude = c('participant_id', 'visit'))
variable n Placebo (Group A) Treatment (Group B) normality test p_value
sex A:153, B:147 Male: 87 (56.9%); Female: 66 (43.1%) Male: 72 (49.0%); Female: 75 (51.0%) NA Chi-squared 0.171
age A:153, B:147 Median (IQR): 43.00 (17.00) Median (IQR): 45.00 (27.00) A:<0.001, B:<0.001 Mann-Whitney U 0.811
weight A:153, B:147 Median (IQR): 67.60 (18.10) Median (IQR): 74.90 (21.50) A:<0.001, B:0.002 Mann-Whitney U 0.002
biomarker A:153, B:147 Mean (SD): 48.96 (9.67) Mean (SD): 47.26 (9.69) A:0.588, B:0.694 Welch's t-test 0.131
response A:153, B:147 Complete: 36 (23.5%); Partial: 36 (23.5%); None: 81 (52.9%) Complete: 52 (35.4%); Partial: 34 (23.1%); None: 61 (41.5%) NA Chi-squared 0.059
# Grouped summary by treatment group with all stats and effect size summary_table(clinical_df, group_by = 'treatment', all = TRUE, effect_size = TRUE, exclude = c('participant_id', 'visit'))
variable n Placebo (Group A) Treatment (Group B) normality test p_value effect_size effect_param
sex A:153, B:147 Male: 87 (56.9%); Female: 66 (43.1%) Male: 72 (49.0%); Female: 75 (51.0%) NA Chi-squared 0.171 0.08 Cramer's V
age A:153, B:147 Mean (SD): 44.80 (13.7); Median (IQR): 43.00 (36.0,53.0); Range: 18.00,79.00 Mean (SD): 43.82 (16.2); Median (IQR): 45.00 (30.0,57.0); Range: 18.00,74.00 A:<0.001, B:<0.001 Mann-Whitney U 0.811 0.89 r
weight A:153, B:147 Mean (SD): 70.70 (14.4); Median (IQR): 67.60 (61.7,79.8); Range: 45.00,105.70 Mean (SD): 75.12 (14.4); Median (IQR): 74.90 (65.7,87.2); Range: 45.00,102.60 A:<0.001, B:0.002 Mann-Whitney U 0.002 1.08 r
biomarker A:153, B:147 Mean (SD): 48.96 (9.7); Median (IQR): 48.92 (42.0,55.7); Range: 21.96,70.24 Mean (SD): 47.26 (9.7); Median (IQR): 47.14 (40.8,53.2); Range: 24.07,75.67 A:0.588, B:0.694 Welch's t-test 0.131 0.17 Cohen's d
response A:153, B:147 Complete: 36 (23.5%); Partial: 36 (23.5%); None: 81 (52.9%) Complete: 52 (35.4%); Partial: 34 (23.1%); None: 61 (41.5%) NA Chi-squared 0.059 0.14 Cramer's V