Learn R Programming

epitabulate (version 0.1.0)

add_mr: Add mortality rate statistics to a gtsummary table

Description

This function wraps gtsummary::add_stat() to calculate and display mortality rates (deaths per given population multiplier) with 95% confidence intervals, using the epitabulate::mortality_rate() function internally.

Usage

add_mr(
  gts_object,
  deaths_var,
  population = NULL,
  multiplier = 10^4,
  drop_tblsummary_stat = FALSE
)

Value

A modified gtsummary object with additional columns showing the number of deaths, population, mortality rate, and 95% confidence interval.

Arguments

gts_object

A gtsummary object created with functions such as gtsummary::tbl_summary() or gtsummary::tbl_cross().

deaths_var

A logical variable name in the data indicating death status (e.g. TRUE for death).

population

Optional numeric vector giving the population size for the denominator. If NULL, the population is inferred from the data.

multiplier

Numeric multiplier used to scale the mortality rate (e.g. 1 = proportion, 100 = percent, 10^4 = per 10,000).

drop_tblsummary_stat

Logical; if TRUE, removes the original tbl_summary statistic column (default = FALSE).