Gtsummary Table with incidence rate

19 Views Asked by At

I want to create a Gtsummary table with trend over time. I have a table with number of cases per year in each group and want to change these numbers to incidence rate. What is the best approach?

I dit try to adjust direclty in mutate, but that did not work.

The code looks like this: 


dataset <- data.frame(
  case_year = rep(1950:1959, each = 300/10),
  numbers = sample(1:300, 300, replace = TRUE)
)




### mutating data for gtsummary table

dataset2 <- dataset %>%
  mutate(numbers_0_100 = numbers <= 100,
         numbers_101_200 = numbers >= 101 & numbers <= 200,
         numbers_201_300 = numbers >= 201)

population_data <- data.frame(
  case_year = rep(1950:1959, each = 300/10),
  population_all = rep(5000, 300),
  population_0_100 = rep(2000, 300),
  population_101_200 = rep(1500, 300),
  population_201_300 = rep(1000, 300)
)

final_dataset <- merge(dataset2, population_data, by = "case_year")

### creating the table

dataset2 %>% 
  select(case_year, numbers_0_100, numbers_101_200, numbers_201_300) %>%
  gtsummary::tbl_summary(by = case_year)

I want this this table with number of cases per group over time, changed to incidence rate (number of cases per 100k population)

0

There are 0 best solutions below