How to know the number of observations used to calculate p-value in gtsummary table with paired p-value?

19 Views Asked by At

I'm using gtsummary to display my data, however, I have some missing values that gets omitted when caluclating the p-value, for that I get this message:

Note for variable 'differ': Some observations included in the calculation of summary statistics were omitted from the p-value calculation due to unbalanced missingness within group.

I want to present the n for only paired observations, rather than summing preop and postop values from the following example, I want n to say "44", rather than "100", for example:

enter image description here

require(dplyr)
require(gtsummary)

data_sample <- structure(list(id = c(104L, 107L, 118L, 118L, 119L, 120L, 120L, 
                              122L, 124L, 125L, 127L, 128L, 145L, 146L, 147L, 149L, 172L, 173L, 
                              174L, 175L, 175L, 176L, 176L, 178L, 178L, 181L, 181L, 182L, 182L, 
                              183L, 183L, 184L, 185L, 185L, 186L, 186L, 187L, 187L, 188L, 188L, 
                              190L, 190L, 192L, 192L, 195L, 195L, 196L, 196L, 197L, 197L, 198L, 
                              198L, 199L, 200L, 200L, 201L, 201L, 202L, 202L, 204L, 204L, 205L, 
                              205L, 206L, 206L, 207L, 208L, 208L, 209L, 209L, 210L, 210L, 211L, 
                              211L, 212L, 212L, 213L, 213L, 214L, 214L, 215L, 215L, 217L, 217L, 
                              219L, 219L, 221L, 221L, 223L, 223L, 224L, 224L, 225L, 225L, 226L, 
                              226L, 227L, 227L, 228L, 228L), visit = structure(c(1L, 1L, 1L, 
                                                                                 2L, 2L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
                                                                                 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 2L, 1L, 2L, 1L, 
                                                                                 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 
                                                                                 2L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 2L, 1L, 
                                                                                 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 
                                                                                 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 
                                                                                 2L), levels = c("Preop", "postop"), class = "factor"), 
                       differ = c(6, 5, 6, 2, 5, 6, 1, 6, 4, 4, 4, 5, 1, 1, 1, 
                                     2, 1, 1, 4, 6, 1, 1, 1, 4, 1, 2, 1, 6, 5, 3, 1, 1, 5, 2, 
                                     6, 1, 6, 1, 5, 2, 1, 1, 6, 1, 2, 1, 2, 1, 1, 1, 6, 1, 1, 
                                     4, 5, 3, 2, 1, 1, 1, 1, 4, 1, 2, 1, 4, 1, 1, 1, 1, 2, 1, 
                                     3, 1, 4, 4, 2, 1, 4, 1, 4, 3, 6, 1, 1, 1, 2, 1, 3, 1, 2, 
                                     1, 3, 1, 6, 1, 1, 1, 1, 1)), row.names = c(NA, -100L), class = c("tbl_df", 
                                                                                                      "tbl", "data.frame"))
data_sample %>% 
  tbl_summary(
    by = visit,
    include = differ,
    type = differ ~ "continuous",
    missing = "ifany",
  ) %>%
  add_n() %>%
  add_difference(test = everything() ~ 'paired.t.test'  ,
                 group ="id") %>% 
  bold_p() 
0

There are 0 best solutions below