I've been using the gtsummary package to create tables for my logistic regressions. I've successfully created two separate tables based on two different models (males and female separately), and I've managed to include number of observations per level in both of them. However when I merge the tables, the number of observations (N) disappear from both models. The code I've been using to create the individual regression tables are these:
#simple log reg with only males
log_gender_M <- glm(SRH_05_2gr ~ smoking_05,
data = Male,
family = "binomial")
#regression table for male log reg
model_M <- tbl_regression(log_gender_M, exponentiate = TRUE)
model_M %>%
modify_header(update = label ~ "**Characteristic (N = {n})**") %>%
bold_labels() %>%
add_n(location = "level") %>%
as_gt() %>%
gt::tab_source_note(gt::md("*Data drawn from the 2005 Scania Survey*")) %>%
gt::tab_header("Males")
The issue with (N) occurs when I merge the regressions
#merging log reg models for males and females
tbl_merge(
tbls = list(model_M, model_F),
tab_spanner = c("Males", "Females")) %>%
add_n(location = "level")
When I use the function add_n() with the above code I receive the following response:
Error in UseMethod("add_n") :
no applicable method for 'add_n' applied to an object of class "c('tbl_merge', 'gtsummary')"
Does anyone know how this might be fixed? I'm quite new to this. Thanks a lot in advance!
