Creating a separate table for how much data for each variable is missing [n(%age missing)]

Viewed 44

I have been asked by a journal to provide how much of the data in a large Table 1 is complete and how much is missing, in a separate supplementary table.

Ideally like:

Variable Group 1 (n = 128) Group 2 (n=100)
Age 128 (100%) 100 (100%)
Sex 64 (50%) 75 (75%)

and so on...

Each variable is formatted as n(percentage complete) in the table.

I know about the missing = "if any" and have been using that, but I can't find a way even with the modify() commands to make a table with just this info. They don't want add_n() style total numbers and missing information in the Table 1 within the manuscript itself.

Is there a relatively straightforward that I am missing and can do this?

1 Answers

You can first replace each column with a logical indicating whether the value is missing (i.e. NA), then pass the table to tbl_summary() for the missing rates to be tabulated.

library(gtsummary)
library(tidyverse)
packageVersion("gtsummary")
#> [1] '1.5.2'

# first make an indicator if a value is missing
trial %>%
  mutate(across(.cols = -trt, .fns = is.na)) %>%
  # then createa summary table tabulating missing data rates
  tbl_summary(by = trt) %>%
  modify_caption("Missing Data Counts") %>%
  as_kable()
Characteristic Drug A, N = 98 Drug B, N = 102
age 7 (7.1%) 4 (3.9%)
marker 6 (6.1%) 4 (3.9%)
stage 0 (0%) 0 (0%)
grade 0 (0%) 0 (0%)
response 3 (3.1%) 4 (3.9%)
death 0 (0%) 0 (0%)
ttdeath 0 (0%) 0 (0%)

Missing Data Counts

Created on 2022-02-04 by the reprex package (v2.0.1)

Related