I have a summary table of IRRs and 95% CI following univariable and multivariable Poisson regression, created with gtsummary that looks a bit like this.
For a logistic regression model it is pretty straightforward to use tbl_summary to create some count data to append to the left of the table. However for a Poisson model I'd like to be able to sum, rather than count, the number of days at risk and the number of events. Each row of the underlying dataset contains a number of days at risk and a number of events, such that the regression model is run like this:
glm(events ~ study_arm + strata_group,
offset = log(days_at_risk),
family=poisson(link = "log"),
data = df)
Is it possible to use gtsummary to create two columns with sums of the number of events and the number of days at risk for each of the rows of the table? (This can then be added to my table using tbl_merge.)
Here is a more complete example of what I'd like to achieve
df = tibble(
study_arm = c("control", "intervention", "control", "intervention", "control", "intervention", "control", "intervention"),
events = c(3,4,12,6,0,3,11,9),
strata_group = c("A", "A", "A", "A", "B", "B", "B", "B"),
days_at_risk = c(100,100,200,200,300,300,100,100)
)
m=glm(events ~ study_arm + strata_group,
offset = log(days_at_risk),
family=poisson(link = "log"),
data = df)
tbl_regression(m, exponentiate = T)
#this is the summary I wish to be able to generate with tbl_summary so I can merge it with the tbl_regression output
bind_rows(
df %>% group_by(study_arm) %>%
summarise(n_events = sum(events),
total_days_at_risk = sum(days_at_risk),
rate=n_events/total_days_at_risk) %>%
mutate(row_group = "study_arm") %>% rename(characteristic=study_arm),
df %>% group_by(strata_group) %>%
summarise(n_events = sum(events),
total_days_at_risk = sum(days_at_risk),
rate=n_events/total_days_at_risk) %>%
mutate(row_group = "strata_group") %>% rename(characteristic=strata_group)
) %>%
select(row_group, characteristic, n_events, total_days_at_risk, rate)