Learn R Programming

epitabulate (version 0.1.0)

add_ar: Add attack rate statistics to a gtsummary table

Description

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

Usage

add_ar(
  gts_object,
  case_var,
  population = NULL,
  multiplier = 10^4,
  drop_tblsummary_stat = FALSE
)

Value

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

Arguments

gts_object

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

case_var

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

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 attack 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).