This is a thin wrapper of gtsummary::tbl_summary() with the following differences:

  • Default summary type for continuous variables is 'continuous2'.

  • Number of non-missing observations, when requested, is added for each variable and placed on the row under the variable label/header.

  • The tbl_summary(missing*) arguments have been renamed to tbl_roche_summary(nonmissing*) with updated default values.

  • The default footnotes from tbl_summary() are removed.

  • Cells with "0 (0.0%)" are converted to "0" with gtsummary::modify_post_fmt_fun().

tbl_roche_summary(
  data,
  by = NULL,
  label = NULL,
  statistic = list(gtsummary::all_continuous() ~ c("{mean} ({sd})", "{median}",
    "{min} - {max}"), gtsummary::all_categorical() ~ "{n} ({p}%)"),
  digits = NULL,
  type = NULL,
  value = NULL,
  nonmissing = c("no", "always", "ifany"),
  nonmissing_text = "n",
  nonmissing_stat = "{N_nonmiss}",
  sort = gtsummary::all_categorical(FALSE) ~ "alphanumeric",
  percent = c("column", "row", "cell"),
  include = everything()
)

Arguments

data

(data.frame)
A data frame.

by

(tidy-select)
A single column from data. Summary statistics will be stratified by this variable. Default is NULL.

label

(formula-list-selector)
Used to override default labels in summary table, e.g. list(age = "Age, years"). The default for each variable is the column label attribute, attr(., 'label'). If no label has been set, the column name is used.

statistic

(formula-list-selector)
Specifies summary statistics to display for each variable. The default is list(all_continuous() ~ "{median} ({p25}, {p75})", all_categorical() ~ "{n} ({p}%)"). See below for details.

digits

(formula-list-selector)
Specifies how summary statistics are rounded. Values may be either integer(s) or function(s). If not specified, default formatting is assigned via assign_summary_digits(). See below for details.

type

(formula-list-selector)
Specifies the summary type. Accepted value are c("continuous", "continuous2", "categorical", "dichotomous"). If not specified, default type is assigned via assign_summary_type(). See below for details.

value

(formula-list-selector)
Specifies the level of a variable to display on a single row. The gtsummary type selectors, e.g. all_dichotomous(), cannot be used with this argument. Default is NULL. See below for details.

nonmissing, nonmissing_text, nonmissing_stat

Arguments dictating how and if missing values are presented:

  • nonmissing: must be one of c("always", "ifany", "no")

  • nonmissing_text: string indicating text shown on non-missing row. Default is "n"

  • nonmissing_stat: statistic to show on non-missing row. Default is "{N_nonmiss}". Possible values are N_nonmiss, N_miss, N_obs, p_nonmiss p_miss.

sort

(formula-list-selector)
Specifies sorting to perform for categorical variables. Values must be one of c("alphanumeric", "frequency"). Default is all_categorical(FALSE) ~ "alphanumeric".

percent

(string)
Indicates the type of percentage to return. Must be one of c("column", "row", "cell"). Default is "column".

In rarer cases, you may need to define/override the typical denominators. In these cases, pass an integer or a data frame. Refer to the ?cards::ard_tabulate(denominator) help file for details.

include

(tidy-select)
Variables to include in the summary table. Default is everything().

Value

a 'gtsummary' table

Examples

# Example 1 ----------------------------------
trial |>
  tbl_roche_summary(
    by = trt,
    include = c(age, grade),
    nonmissing = "always"
  ) |>
  add_overall()
All Participants
(N = 200)
Drug A
(N = 98)
Drug B
(N = 102)
Age


    n 189 91 98
    Mean (SD) 47 (14) 47 (15) 47 (14)
    Median 47 46 48
    Min - Max 6 - 83 6 - 78 9 - 83
Grade


    n 200 98 102
    I 68 (34.0%) 35 (35.7%) 33 (32.4%)
    II 68 (34.0%) 32 (32.7%) 36 (35.3%)
    III 64 (32.0%) 31 (31.6%) 33 (32.4%)