gtsummarytools is a package to modify gtsummary tables notably by including the number of non missing observations.
background: gtsummary shows total Ns by default, which can lead to confusion, especially with regards the calculation of percentages in the presence of missing data.
gtsummarytools is easiest to install via
Linux users might have to install from source:
remotes::install_github("dcr-unibe-ch/gtsummarytools")This may require Sys.setenv(R_REMOTES_NO_ERRORS_FROM_WARNINGS="true") if packages were built under a different R version to the one you are using.
library(gtsummarytools)gtsummary tables of class “tbl_summary” show total Ns by default, which can lead to confusion, especially with regards the calculation of percentages in the presence of missing data.
For ungrouped datasets (i.e. no by argument in tbl_summary), using add_n is sufficient. For grouped datasets (tbl_summary(by = something)), additional columns with the observed Ns can be added, but it requires a few lines of code.
the function add_nobs in gtsummarytools allow to add the Nobs (i.e. number of non-missing data) to a table of class c(‘tbl_summary’, ‘gtsummary’), generated by tbl_summary. Depending on the specified location Nobs will be: