Function takes a time at risk variable (time
) and event count variable (count
) and calculates the incidence
rate in person-years.
Incidence rate is calculated as: Total number of events that occurred / Total person-time at risk
Usage
ard_incidence_rate(
data,
time,
count = NULL,
id = NULL,
by = NULL,
strata = NULL,
n_person_time = 100,
unit_label = "time",
conf.level = 0.95,
conf.type = c("normal", "normal-log", "exact", "byar")
)
Arguments
- data
(
data.frame
)
a data frame.- time
(
tidy-select
)
column name of time at risk variable.- count
(
tidy-select
)
column name of variable indicating count of events that occurred. IfNULL
, each row indata
is assumed to correspond to a single event occurrence.- id
(
tidy-select
)
column name used to identify unique subjects indata
. IfNULL
, each row indata
is assumed to correspond to a unique subject.- by, strata
-
(
tidy-select
)
columns to tabulate by/stratify by for summary statistic calculation. Arguments are similar, but with an important distinction:by
: results are calculated for all combinations of the columns specified, including unobserved combinations and unobserved factor levels.strata
: results are calculated for all observed combinations of the columns specified.Arguments may be used in conjunction with one another.
- n_person_time
(
numeric
)
amount of person-time to estimate incidence rate for. Defaults to 100.- unit_label
(
string
)
label for the unit of values intime
and estimated person-time output (e.g."years"
for person-years,"days"
for person-days, etc.). If the desired person-time estimate unit does not match the currenttime
unit, values oftime
should be converted to the correct unit during pre-processing. Defaults to"time"
(person-time).- conf.level
(
numeric
)
confidence level for the estimated incidence rate.- conf.type
-
(
string
)
confidence interval type for the estimated incidence rate.One of:
normal
(default),normal-log
,exact
, orbyar
.
Details
The formulas used to calculate the confidence interval for each CI type are as follows, where \(x_i\) and \(t_i\) represent the number of events and follow-up time for subject \(i\), respectively.
-
byar
: Byar's approximation of a Poisson CI. A continuity correction of 0.5 is included in the calculation.$$CI = (\sum{x_i} + 0.5) (1 - 1 / (9 \times (\sum{x_i} + 0.5)) \pm Z_{1 - \alpha / 2} / (3 \sqrt{\sum{x_i} + 0.5}))^3 / \sum{t_i}$$
-
normal
: Normal CI.$$CI = \sum{x_i} / \sum{t_i} \pm Z_{1 - \alpha / 2} \sqrt{\sum{x_i}} / \sum{t_i}$$
-
normal-log
: Normal-Log CI.$$CI = \exp(\log(\sum{x_i} / \sum{t_i}) \pm Z_{1 - \alpha / 2} / \sqrt{\sum{x_i}})$$
-
exact
: Exact CI for a Poisson mean.$$CI_{lower} = \chi^2_{\alpha / 2, 2\sum{x_i} + 2} / {2 \sum{t_i}}$$ $$CI_{upper} = \chi^2_{1 - \alpha / 2, 2\sum{x_i} + 2} / {2 \sum{t_i}}$$
Examples
set.seed(1)
data <- data.frame(
USUBJID = 1:100,
TRTA = sample(LETTERS[1:3], 100, replace = TRUE),
AETTE1 = abs(rnorm(100, mean = 0.5)),
AETOT1 = sample(0:20, 100, replace = TRUE)
)
data |>
ard_incidence_rate(time = AETTE1, count = AETOT1, id = USUBJID, by = TRTA, unit_label = "years")
#> {cards} data frame: 27 x 10
#> group1 group1_level variable stat_name stat_label stat
#> 1 TRTA A AETTE1 estimate Incidenc… 976.305
#> 2 TRTA A AETTE1 std.error Standard… 0.578
#> 3 TRTA A AETTE1 conf.low CI Lower… 862.958
#> 4 TRTA A AETTE1 conf.high CI Upper… 1089.653
#> 5 TRTA A AETTE1 conf.type CI Type normal
#> 6 TRTA A AETTE1 conf.level CI Confi… 0.95
#> 7 TRTA A AETTE1 tot_person_time Person-Y… 29.192
#> 8 TRTA A AETTE1 n_events Number o… 285
#> 9 TRTA A AETTE1 N Number o… 33
#> 10 TRTA B AETTE1 estimate Incidenc… 1373.986
#> ℹ 17 more rows
#> ℹ Use `print(n = ...)` to see more rows
#> ℹ 4 more variables: context, fmt_fun, warning, error