|
| 1 | +# Suppress CMD check notes for NSE variables and base functions used across gtsummary wrapper functions |
| 2 | +utils::globalVariables(c( |
| 3 | + "case_n", # column name created in dplyr operations |
| 4 | + "deaths_n", # column name created in dplyr operations |
| 5 | + "Cases", # column name in gtsummary table_body |
| 6 | + "Deaths", # column name in gtsummary table_body |
| 7 | + "mortality per 10 000" # column name created by mortality_rate function |
| 8 | +)) |
1 | 9 |
|
2 | | -#' A mortality rate wrapper function (using the gtsummary package)that takes |
3 | | -#' a gtsummary object and returns a gtsummary object with attack rate (per given |
4 | | -#' multiple) with 95% confidence interval |
5 | | -#' |
6 | | -#' @param gts_object A data frame, passed by the gtsummary::add_stat function. |
7 | | -#' |
8 | | -#' @param deaths_var logical variable name that indicates deaths |
9 | | -#' |
10 | | -#' @param variable Name of a variable as the outcome of interest, passed by the |
11 | | -#' gtsummary::add_stat function (e.g. illness) |
12 | | -#' |
13 | | -#' @param by Name of a variable for stratifying, passed by the gtsummary::add_stat |
14 | | -#' function (e.g. illness). |
| 10 | + |
| 11 | + |
| 12 | +#' Add mortality rate statistics to a gtsummary table |
15 | 13 | #' |
16 | | -#'#'@param population the number of individuals in the population, passed to |
17 | | -#'`epitabulate::mortality_rate` |
| 14 | +#' This function wraps `gtsummary::add_stat()` to calculate and display |
| 15 | +#' **mortality rates** (deaths per given population multiplier) with 95% |
| 16 | +#' confidence intervals, using the `epitabulate::mortality_rate()` function |
| 17 | +#' internally. |
18 | 18 | #' |
19 | | -#' @param ... additional params that may be passed from gtsummary functions. |
| 19 | +#' @param gts_object A gtsummary object created with functions such as |
| 20 | +#' `gtsummary::tbl_summary()` or `gtsummary::tbl_cross()`. |
| 21 | +#' @param deaths_var A logical variable name in the data indicating death |
| 22 | +#' status (e.g. `TRUE` for death). |
| 23 | +#' @param population Optional numeric vector giving the population size for |
| 24 | +#' the denominator. If `NULL`, the population is inferred from the data. |
| 25 | +#' @param multiplier Numeric multiplier used to scale the mortality rate |
| 26 | +#' (e.g. `1` = proportion, `100` = percent, `10^4` = per 10,000). |
| 27 | +#' @param drop_tblsummary_stat Logical; if `TRUE`, removes the original |
| 28 | +#' `tbl_summary` statistic column (default = `FALSE`). |
20 | 29 | #' |
21 | | -#' @return a single-row gtsummary object with attack rate results cases, |
22 | | -#' population, attack rate, and 95% confidence interval. |
| 30 | +#' @return A modified gtsummary object with additional columns showing |
| 31 | +#' the number of deaths, population, mortality rate, and 95% confidence |
| 32 | +#' interval. |
23 | 33 | #' |
24 | | -#' @rdname gt_attackrate |
| 34 | +#' @rdname add_mr |
25 | 35 | #' |
26 | 36 | #' @export |
27 | 37 | add_mr <- function(gts_object, |
@@ -89,32 +99,32 @@ add_mr <- function(gts_object, |
89 | 99 | return(gts_object) |
90 | 100 | } |
91 | 101 |
|
92 | | -#' An attack rate wrapper function (using the gtsummary package)that takes |
93 | | -#' a gtsummary object and returns a gtsummary object withattack rate (per given |
94 | | -#' multiple) with 95% confidence interval |
| 102 | +#' Add attack rate statistics to a gtsummary table |
95 | 103 | #' |
96 | | -#' @param gts_object A data frame, passed by the gtsummary::add_stat function. |
| 104 | +#' This function wraps `gtsummary::add_stat()` to calculate and display |
| 105 | +#' **attack rates** (cases per given population multiplier) with 95% confidence |
| 106 | +#' intervals, using the `epitabulate::attack_rate()` function internally. |
97 | 107 | #' |
98 | | -#' @param variable Name of a variable as the outcome of interest, passed by the |
99 | | -#' gtsummary::add_stat function (e.g. illness) |
| 108 | +#' @param gts_object A gtsummary object created with functions such as |
| 109 | +#' `gtsummary::tbl_summary()` |
100 | 110 | #' |
101 | | -#' @param by Name of a variable for stratifying, passed by the gtsummary::add_stat |
102 | | -#' function (e.g. illness). |
| 111 | +#' @param case_var A logical variable name in the data indicating case status |
| 112 | +#' (e.g. `TRUE` for cases). |
103 | 113 | #' |
104 | | -#'#'@param population the number of individuals in the population, passed to |
105 | | -#'`epitabulate::attack_rate` |
106 | 114 | #' |
107 | | -#'@param multiplier The base by which to multiply the output: |
108 | | -# '1: multiplier = 1: ratio between 0 and 1; |
109 | | -# '2: multiplier = 100:proportion; |
110 | | -# '3: multiplier = 10^4: x per 10,000 people; passed to `epitabulate::attack_rate` |
| 115 | +#' @param population Optional numeric vector giving the population size for |
| 116 | +#' the denominator. If `NULL`, the population is inferred from the data. |
111 | 117 | #' |
112 | | -#' @param ... additional params that may be passed from gtsummary functions. |
| 118 | +#' @param multiplier Numeric multiplier used to scale the attack rate |
| 119 | +#' (e.g. `1` = proportion, `100` = percent, `10^4` = per 10,000). |
113 | 120 | #' |
114 | | -#' @return a single-row gtsummary object with attack rate results cases, |
115 | | -#' population, attack rate, and 95% confidence interval. |
| 121 | +#' @param drop_tblsummary_stat Logical; if `TRUE`, removes the original |
| 122 | +#' `tbl_summary` statistic column (default = `FALSE`). |
| 123 | +#' |
| 124 | +#' @return A modified gtsummary object with additional columns showing |
| 125 | +#' the number of cases, population, attack rate, and 95% confidence interval. |
116 | 126 | #' |
117 | | -#' @rdname gt_attackrate |
| 127 | +#' @rdname add_ar |
118 | 128 | #' |
119 | 129 | #' @export |
120 | 130 | #' |
@@ -183,27 +193,21 @@ add_ar <- function(gts_object, |
183 | 193 |
|
184 | 194 |
|
185 | 195 |
|
186 | | -#' An case fatality rate wrapper function (using the gtsummary package) |
187 | | -#' that takes a gtsummary object and returns a gtsummary object with number |
188 | | -#' of deaths, case fatality rate, and 95% confidence interval. |
189 | | -#' |
190 | | -#' @param data A data frame, passed by the gtsummary::add_stat function. |
191 | | -#' |
192 | | -#' @param variable Name of a variable as the outcome of interest, passed by the |
193 | | -#' gtsummary::add_stat function (e.g. illness). |
194 | | -#' |
195 | | -#' @param by Name of a variable for stratifying, passed by the gtsummary::add_stat function |
196 | | -#' (e.g. illness). |
| 196 | +#' Add case fatality rate (CFR) statistics to a gtsummary table |
197 | 197 | #' |
198 | | -#' @param deaths_var the name of a logical column in the data that indicates that the case died, |
199 | | -#' is passed as the first argument to `epitabulate::case_fatality_rate_df` |
200 | | -#' |
201 | | -#' @param ... additional params that may be passed from gtsummary functions. |
| 198 | +#' This function wraps `gtsummary::add_stat()` to calculate and display |
| 199 | +#' **case fatality rates** (deaths among cases) with 95% confidence intervals, |
| 200 | +#' using the `epitabulate::case_fatality_rate_df()` function internally. |
202 | 201 | #' |
203 | | -#' @return a single row gtsummary object with case fatality rate results for |
204 | | -#' deaths, cases, cfr, and 95% confidence interval. |
| 202 | +#' @param gts_object A gtsummary object created with functions such as |
| 203 | +#' `gtsummary::tbl_summary()` or `gtsummary::tbl_cross()`. |
| 204 | +#' @param deaths_var A logical variable name in the data indicating death |
| 205 | +#' status (e.g. `TRUE` for death). |
| 206 | +#' @return A modified gtsummary object with additional columns showing |
| 207 | +#' the number of deaths, number of cases, case fatality rate, and 95% |
| 208 | +#' confidence interval. |
205 | 209 | #' |
206 | | -#' @rdname gt_attackrate |
| 210 | +#' @rdname add_cfr |
207 | 211 | #' @import dplyr |
208 | 212 | #' @export |
209 | 213 | #' |
@@ -247,7 +251,7 @@ add_cfr <- function(gts_object, deaths_var) { |
247 | 251 |
|
248 | 252 | #' @return a gtsummary object without the named column |
249 | 253 | #' |
250 | | -#' @rdname gtsummary_wrappers |
| 254 | +#' @rdname gt_remove_stat |
251 | 255 | #' @export |
252 | 256 | #' |
253 | 257 | gt_remove_stat <- function(gts_object, col_name = "stat_0") { |
@@ -382,6 +386,8 @@ add_gt_cfr_stat_level <- function(data, variable, by, deaths_var, ...) { |
382 | 386 | #' |
383 | 387 | #' @param ... additional params that may be passed from gtsummary functions. |
384 | 388 | #' |
| 389 | +#' @importFrom stats setNames |
| 390 | +#' |
385 | 391 | #' @return a single row gtsummary object with with attack rate results with |
386 | 392 | #' cases, attack rate, and 95% confidence interval. |
387 | 393 | #' |
@@ -459,6 +465,9 @@ add_gt_attack_rate_stat_label <- |
459 | 465 | #' |
460 | 466 | #' @param ... additional params that may be passed from gtsummary functions. |
461 | 467 | #' |
| 468 | +#' @importFrom rlang := |
| 469 | +#' @importFrom stats setNames |
| 470 | +#' |
462 | 471 | #' @return a single-row gtsummary object with attack rate results cases, |
463 | 472 | #' population, attack rate, and 95% confidence interval. |
464 | 473 | #' |
@@ -552,6 +561,9 @@ add_gt_attack_rate_level <- |
552 | 561 | return(ar) |
553 | 562 | } |
554 | 563 |
|
| 564 | + |
| 565 | +#' @importFrom stats setNames |
| 566 | +#' @noRd |
555 | 567 | add_gt_mortality_rate_stat_label <- |
556 | 568 | function(data, variable, by=NULL, deaths_var, population = NULL, |
557 | 569 | multiplier = 10^4, drop_total = TRUE, drop_deaths = TRUE, ...) { |
@@ -629,6 +641,9 @@ add_gt_mortality_rate_stat_label <- |
629 | 641 | #' |
630 | 642 | #' @param ... additional params that may be passed from gtsummary functions. |
631 | 643 | #' |
| 644 | +#' @importFrom rlang := |
| 645 | +#' @importFrom stats setNames |
| 646 | +#' |
632 | 647 | #' @return a single-row gtsummary object with attack rate results cases, |
633 | 648 | #' population, attack rate, and 95% confidence interval. |
634 | 649 | #' |
|
0 commit comments