I would like to put the number of observations included in set of regression models at the bottom of a gtsummary
table, in the same columns as the coefficient estimates. It is straightforward to put the numbers of observations in columns:
library(dplyr)
library(gtsummary)
df <- mtcars %>%
mutate(cyl_miss = if_else(
cyl == 6,
NA_real_,
cyl
))
model_1 <- lm(
data = df,
formula = mpg ~ cyl + disp
)
model_2 <- lm(
data = df,
formula = mpg ~ cyl_miss + disp
)
table_1 <- tbl_regression(model_1) %>%
add_significance_stars(
pattern = "{estimate}{stars}",
thresholds = c(0.001, 0.01, 0.05),
hide_ci = TRUE,
hide_p = TRUE,
hide_se = FALSE
) %>%
add_n()
table_2 <- tbl_regression(model_2) %>%
add_significance_stars(
pattern = "{estimate}{stars}",
thresholds = c(0.001, 0.01, 0.05),
hide_ci = TRUE,
hide_p = TRUE,
hide_se = FALSE
) %>%
add_n()
tbl_merge(
list(table_1, table_2)
)
How can I put the numbers (here 32 and 25) in the Beta columns, in a row labelled "N"?