Skip to contents

A manuscript baseline table with an overall column, one column per stratum and an omnibus test p-value, built on [gtsummary::tbl_summary()] so the result can be styled and exported like any other `gtsummary` table (`gtsummary::as_flex_table()`, `as_gt()`, ...). * categorical variables: `n ( * continuous variables: `mean (SD)`, or `median [Q1, Q3]` for those in `non_normal_vars`; * p-values: Welch's t-test or Welch's one-way ANOVA for the mean (SD) variables, Wilcoxon or Kruskal-Wallis for the median variables, chi-squared or Fisher's exact test for categorical ones (`gtsummary` chooses by the expected counts).

Usage

tbl_table_one(
  data,
  strata = NULL,
  vars = NULL,
  non_normal_vars = NULL,
  test = TRUE,
  overall = TRUE,
  digits = 2,
  p_digits = 3,
  missing = "ifany"
)

Arguments

data

A data frame.

strata

Name of the grouping column (at least two levels in use). `NULL` gives an unstratified table without p-values.

vars

Columns to describe; default all columns except `strata`.

non_normal_vars

Continuous variables shown as median [Q1, Q3] and tested with a rank test.

test

Add the p-value column (default `TRUE`; ignored without `strata`).

overall

Add the overall column (default `TRUE`).

digits

Decimals for continuous statistics.

p_digits

Decimals for p-values.

missing

Passed to [gtsummary::tbl_summary()] (`"ifany"` default).

Value

A `gtsummary` table.

See also

[tbl_two_sample_compare()], [summary_table()]

Examples

d <- mtcars
d$cyl <- factor(d$cyl)
tbl_table_one(d, strata = "cyl", vars = c("mpg", "hp", "am"), non_normal_vars = "hp")
Characteristic Overall
N = 32
1
4
N = 11
1
6
N = 7
1
8
N = 14
1
p-value2
mpg 20.09 (6.03) 26.66 (4.51) 19.74 (1.45) 15.10 (2.56) <0.001
hp 123.00 [96.00, 180.00] 91.00 [65.00, 97.00] 110.00 [110.00, 123.00] 192.50 [175.00, 245.00] <0.001
am



0.009
    0 19 (59%) 3 (27%) 4 (57%) 12 (86%)
    1 13 (41%) 8 (73%) 3 (43%) 2 (14%)
1 Mean (SD); Median [Q1, Q3]; n (%)
2 One-way analysis of means (not assuming equal variances); Kruskal-Wallis rank sum test; Fisher’s exact test