Learn R Programming

⚠️There's a newer version (1.6.3) of this package.Take me there.


A collection of functions commonly used in the work of the biostatisticians. The goal of gtsummary is to make reporting of tabular analytic results simple, beautiful, and reproducible.

Installation

You can install the production version of gtsummary with:

install.packages("remotes")
remotes::install_url("https://github.com/ddsjoberg/clintable/archive/master.zip")

and the development version with:

install.packages("remotes")
remotes::install_url("https://github.com/ddsjoberg/clintable/archive/dev.zip")

Examples

The vignettes/tutorials for the primary gtsummary functions have detailed examples and can be found at danieldsjoberg.com/clintable. Each vignette is an Rmarkdown file (*.Rmd) and a copy of the files can be found here: https://github.com/ddsjoberg/clintable/tree/master/vignettes.

Table 1

library(gtsummary)
fmt_table1(trial, by = "trt") %>% 
  add_comparison() %>% 
  bold_labels()
VariableDrugPlacebop-value
N = 107N = 93
Age, yrs47 (39, 58)46 (36, 54)0.3
Unknown35
Marker Level, ng/mL0.61 (0.22, 1.20)0.72 (0.22, 1.63)0.4
Unknown44
T Stage0.13
T125 (23%)26 (28%)
T226 (24%)23 (25%)
T329 (27%)13 (14%)
T427 (25%)31 (33%)
Grade0.3
I38 (36%)29 (31%)
II34 (32%)24 (26%)
III35 (33%)40 (43%)
Tumor Response52 (51%)30 (33%)0.017
Unknown63

Regression Models

mod1 = glm(am ~ mpg + factor(cyl), mtcars, family = binomial(link = "logit"))
fmt_regression(
  mod1, exponentiate = TRUE, 
  label = list(`factor(cyl)` = "No. of Cylinders", mpg = "Miles per Gallon")
  )
N = 32OR95% CIp-value
Miles per Gallon1.451.03, 2.400.080
No. of Cylinders
4Ref.
62.080.13, 39.00.6
82.020.04, 1190.7

Copy Link

Version

Install

install.packages('gtsummary')

Monthly Downloads

53,670

Version

0.1.0

License

MIT + file LICENSE

Maintainer

Daniel D. Sjoberg

Last Published

May 10th, 2019

Functions in gtsummary (0.1.0)

add_global.fmt_regression

Adds the global p-value for a categorical variables in fmt_regression objects
add_n

Adds a column with N (or N missing) for each variable
assign_summary_type

Assigns summary type (e.g. continuous, categorical, or dichotomous).
assign_dichotomous_value

For dichotomous data, returns that value that will be printed in table.
add_overall

Adds a column with overall summary statistics to an existing fmt_table1 object where descriptive statistics are split by a variable
assign_test

determine the appropriate test type given two variables
fmt_percent

Formats percentages to be displayed in tables or text of report.
assign_stat_display

Assign type of summary statistic
fmt_pvalue

Formats p-values to be displayed in tables or text of report.
add_q

Add a column of q values to objects to account for multiple comparisons
bold_levels.fmt_uni_regression

Bold or unbold variable levels for fmt_uni_regression objects in Rmarkdown
add_global.fmt_uni_regression

Adds the global p-value for a categorical variables in fmt_uni_regression objects
as_tibble.fmt_uni_regression

Convert fmt_uni_regression objects to data frame
assign_class

Extract class of variable
bold_levels.fmt_regression

Bold or unbold variable levels for fmt_regression objects in Rmarkdown
indent_key.fmt_regression

Makes index of factor variables requiring indent from fmt_regression objects in Rmarkdown
bold_p

Bold significant p-values in Rmarkdown
add_q.fmt_table1

Add a column of q values to fmt_table1 object to account for multiple comparisons in Rmarkdown
assign_var_label

Assigns variable label to display.
add_stat_label

Adds a column showing a label for the summary statistics shown in each row
bold_levels.fmt_table1

Bold or unbold variable levels for fmt_table1 objects in Rmarkdown
indent_key.fmt_table1

Makes index of factors requiring indent from fmt_table1 objects in Rmarkdown
calculate_summary_stat

This function takes in the meta data table, and calls the appropriate summarize function.
as_data_frame

The tibble package's as_data_frame function is an alias for tibble::as_tibble
italicize_labels.fmt_table1

Italicize or unitalicize labels for fmt_table1 objects in Rmarkdown
continuous_digits_guess

Guesses how many digits to use in rounding continuous variables or summary statistics
gtsummary-package

gtsummary: Presentation-Ready Data Summary Tables
italicize_labels.fmt_uni_regression

Italicize or unitalicize labels for fmt_uni_regression objects in Rmarkdown
as_tibble.fmt_regression

Convert fmt_regression objects to data frame
as_tibble.fmt_table1

Convert fmt_table1 objects to data frame
indent_key

as_tibble

The tibble package's as_tibble function
modify_header.fmt_table1

Modifies header rows for existing fmt_table1 objects.
bold_labels.fmt_regression

Bold or unbold variable labels for fmt_regression objects in Rmarkdown
bold_labels.fmt_uni_regression

Bold or unbold variable labels for fmt_uni_regression objects in Rmarkdown
bold_levels

Bold variable levels in Rmarkdown
bold_p.fmt_regression

Bold or unbold p-values for fmt_regression objects in Rmarkdown
bold_labels

Bold variable labels in Rmarkdown
fmt_beta

Round and format regression model coefficients
create_header

Creates header rows for fmt_table1 of fmt_regression objects
modify_header.fmt_uni_regression

Modifies header rows for existing fmt_uni_regression objects.
fmt_regression

Turn a regression model object into a markdown-ready tibble.
italicize_levels

Italicize variable levels in Rmarkdown
%>%

magrittr Pipe operator %>%
bold_labels.fmt_table1

Bold or unbold variable labels for fmt_table1 objects in Rmarkdown
print.fmt_regression

Print fmt_regression objects
italicize_levels.fmt_regression

Italicize or unitalicize levels for fmt_regression objects in Rmarkdown
get_by_info

trial

Results from a simulated trial of Placebo vs Drug
%T>%

Tee operator
bold_p.fmt_uni_regression

Bold or unbold p-values for fmt_uni_regression objects in Rmarkdown
bold_p.fmt_table1

Bold or unbold p-values for fmt_table1 objects in Rmarkdown
italicize_labels

Italicize variable labels in Rmarkdown
italicize_labels.fmt_regression

Italicize or unitalicize labels for fmt_regression objects in Rmarkdown
fmt_table1_header

This function creates header rows for fmt_table1 objects
fmt_uni_regression

Creates table of univariate regression results
italicize_levels.fmt_table1

Italicize or unitalicize levels for fmt_table1 objects in Rmarkdown
inline_text.fmt_regression

Report statistics from fmt_regression and fmt_uni_regression inline in an Rmarkdown document
inline_text.fmt_table1

Report statistics from fmt_table1 inline in an Rmarkdown document
italicize_levels.fmt_uni_regression

Italicize or unitalicize levels for fmt_uni_regression objects in Rmarkdown
calculate_pvalue

This function takes in the meta-data and calculates an appropriate p-value
modify_header

Modifies header rows for existing fmt_table1, fmt_regression, and fmt_uni_regression objects
modify_header.fmt_regression

Modifies header rows for existing fmt_regression objects.
knit_print

A custom printing function for Rmarkdown
summarize_continuous

Calculates and formats summary statistics for continuous data
row_to_name

Renames columns to values in a row of data frame
summarize_categorical

Calculates and formats N's and percentages for categorical and dichotomous data
tidy_wrap

Tidies regression object based on class
knit_print.fmt_regression

Print fmt_regression objects in Rmarkdown
fmt_table1

Calculates and formats descriptive statistics for Table 1.
print.fmt_table1

Print fmt_table1 objects
indent_key.fmt_uni_regression

Makes index of factor variables requiring indent from fmt_regression objects in Rmarkdown
print.fmt_uni_regression

Print fmt_uni_regression objects
inline_text

Report statistics from fmt_table1 and fmt_regression inline in an Rmarkdown document
knit_print.fmt_table1

Print fmt_table1 objects in Rmarkdown
knit_print.fmt_uni_regression

Print fmt_uni_regression objects in Rmarkdown
null-default

Default value for NULL.
parse_terms

Convert a regression model object to a parsed list matching model terms to variable names
add_comparison

Adds p-values to the output comparing values across groups
add_global

Adds the global p-value for a categorical variables
add_q.fmt_uni_regression

Add a column of q values to fmt_uni_regression object to account for multiple comparisons