| Title: | Tables for Epidemiological Analysis |
|---|---|
| Description: | Produces tables for descriptive epidemiological analysis. These tables include attack rates, case fatality ratios, and mortality rates (with appropriate confidence intervals), with additional functionality to calculate Mantel-Haenszel odds, risk, and incidence rate ratios. The methods implemented follow standard epidemiological approaches described in Rothman et al. (2008, ISBN:978-0-19-513554-2). This package is part of the 'R4EPIs' project <https://R4EPI.github.io/sitrep/>. |
| Authors: | Alexander Spina [aut, cre] (ORCID: <https://orcid.org/0000-0001-8425-1867>), Zhian N. Kamvar [aut] (ORCID: <https://orcid.org/0000-0003-1458-7108>), Amy Gimma [aut], Kate Doyle [ctb], Applied Epi Incorporated [cph], Medecins Sans Frontieres Operational Centre Amsterdam [fnd] |
| Maintainer: | Alexander Spina <[email protected]> |
| License: | GPL-3 |
| Version: | 0.1.0 |
| Built: | 2026-05-13 09:42:08 UTC |
| Source: | https://github.com/r4epi/epitabulate |
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.
add_ar( gts_object, case_var, population = NULL, multiplier = 10^4, drop_tblsummary_stat = FALSE )add_ar( gts_object, case_var, population = NULL, multiplier = 10^4, drop_tblsummary_stat = FALSE )
gts_object |
A gtsummary object created with functions such as
|
case_var |
A logical variable name in the data indicating case status
(e.g. |
population |
Optional numeric vector giving the population size for
the denominator. If |
multiplier |
Numeric multiplier used to scale the attack rate
(e.g. |
drop_tblsummary_stat |
Logical; if |
A modified gtsummary object with additional columns showing the number of cases, population, attack rate, and 95% confidence interval.
This function wraps gtsummary::add_stat() to calculate and display
case fatality rates (deaths among cases) with 95% confidence intervals,
using the epitabulate::case_fatality_rate_df() function internally.
add_cfr(gts_object, deaths_var)add_cfr(gts_object, deaths_var)
gts_object |
A gtsummary object created with functions such as
|
deaths_var |
A logical variable name in the data indicating death
status (e.g. |
A modified gtsummary object with additional columns showing the number of deaths, number of cases, case fatality rate, and 95% confidence interval.
A {gtsummary} wrapper function that takes a gtsummary univariate regression table and adds appropriate cross tabs by exposure and outcome
add_crosstabs(x, wide = FALSE)add_crosstabs(x, wide = FALSE)
x |
Object with class |
wide |
TRUE/FALSE to specify whether would like to have the output in wide format. Results in four columns rather than two, but in a single row. This is only works for dichotomous variables (yes/no, TRUE/FALSE, male/female), others will be dropped with a warning message. (Default is FALSE) |
A modified gtsummary table object (same class as input — e.g.
"tbl_uvregression" or "tbl_cmh") containing additional cross-tabulated
counts of outcomes and exposures. The structure depends on regression type:
For logistic models: adds case and control counts.
For Poisson models without offsets: adds total and case counts per exposure group (risk ratios).
For Poisson models with offsets: adds total person-time and case counts per exposure group (incidence rate ratios).
When wide = TRUE, dichotomous variables are reshaped to wide format with separate columns for exposed/unexposed counts.
Inspired by Daniel Sjoberg, see gtsummary github repo
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.
add_mr( gts_object, deaths_var, population = NULL, multiplier = 10^4, drop_tblsummary_stat = FALSE )add_mr( gts_object, deaths_var, population = NULL, multiplier = 10^4, drop_tblsummary_stat = FALSE )
gts_object |
A gtsummary object created with functions such as
|
deaths_var |
A logical variable name in the data indicating death
status (e.g. |
population |
Optional numeric vector giving the population size for
the denominator. If |
multiplier |
Numeric multiplier used to scale the mortality rate
(e.g. |
drop_tblsummary_stat |
Logical; if |
A modified gtsummary object with additional columns showing the number of deaths, population, mortality rate, and 95% confidence interval.
Calculate attack rate, case fatality rate, and mortality rate
attack_rate( cases, population, conf_level = 0.95, multiplier = 100, mergeCI = FALSE, digits = 2 ) case_fatality_rate( deaths, population, conf_level = 0.95, multiplier = 100, mergeCI = FALSE, digits = 2 ) case_fatality_rate_df( x, deaths, group = NULL, conf_level = 0.95, multiplier = 100, mergeCI = FALSE, digits = 2, add_total = FALSE ) mortality_rate( deaths, population, conf_level = 0.95, multiplier = 10^4, mergeCI = FALSE, digits = 2 )attack_rate( cases, population, conf_level = 0.95, multiplier = 100, mergeCI = FALSE, digits = 2 ) case_fatality_rate( deaths, population, conf_level = 0.95, multiplier = 100, mergeCI = FALSE, digits = 2 ) case_fatality_rate_df( x, deaths, group = NULL, conf_level = 0.95, multiplier = 100, mergeCI = FALSE, digits = 2, add_total = FALSE ) mortality_rate( deaths, population, conf_level = 0.95, multiplier = 10^4, mergeCI = FALSE, digits = 2 )
cases, deaths
|
number of cases or deaths in a population. For |
population |
the number of individuals in the population. |
conf_level |
a number representing the confidence level for which to
calculate the confidence interval. Defaults to 0.95, representing a 95%
confidence interval using |
multiplier |
The base by which to multiply the output:
|
mergeCI |
Whether or not to put the confidence intervals in one column (default is FALSE) |
digits |
if |
x |
a data frame |
group |
the bare name of a column to use for stratifying the output |
add_total |
if |
a data frame with five columns that represent the numerator, denominator, rate, lower bound, and upper bound.
attack_rate(): cases, population, ar, lower, upper
case_fatality_rate(): deaths, population, cfr, lower, upper
A gtsummary wrapper function that takes a gtsummary object and removes a column from the table body by column name
gt_remove_stat(gts_object, col_name = "stat_0")gt_remove_stat(gts_object, col_name = "stat_0")
gts_object |
A data frame, passed by the gtsummary::add_stat function |
col_name |
the column name from the gtsummary object's table_body to remove |
a gtsummary object without the named column
A {gtsummary} wrapper function that takes a dataframe and produces crude, stratified and Cochran-Mantel-Haenszel estimates.
tbl_cmh( data, case, exposure, strata, measure, obstime = NULL, conf.level = 0.95 )tbl_cmh( data, case, exposure, strata, measure, obstime = NULL, conf.level = 0.95 )
data |
A data frame |
case |
Name of a variable as your outcome of interest |
exposure |
Names of variables as exposures of interest. Can be multiple variables using tidyselect syntax. |
strata |
Name of a variable to be used for stratifying results. This gives you a table of crude measure, measures for each strata and the mantel-haeszel adjusted measure for each exposure variable |
measure |
Specify what you would like to calculated, options are "OR", "RR" or "IRR". Default is "OR". If "OR or "RR" are specified then a woolf test for homogeneity p-value is produced. This tests whether there is a significant difference in the estimates between strata. |
obstime |
A numeric variable containing the observation time for each individual |
conf.level |
Confidence level for confidence intervals (default 0.95) |
A gtsummary table of class "tbl_cmh" (and "gtsummary", "tbl_stack")
containing:
Crude estimates of association (odds ratios, risk ratios, or rate ratios)
Stratified estimates for each level of the stratification variable
Cochran–Mantel–Haenszel (CMH) adjusted estimates with 95\
Woolf test p-values for assessing homogeneity across strata (when applicable)
Inspired by Daniel Sjoberg, see gtsummary github repo