Estimate the event rate adjusted for person-years at risk, otherwise known as incidence rate. Primary analysis variable is the person-years at risk.
Usage
s_incidence_rate(
df,
.var,
n_events,
is_event,
control = control_incidence_rate()
)
a_incidence_rate(
df,
.var,
n_events,
is_event,
control = control_incidence_rate()
)
estimate_incidence_rate(
lyt,
vars,
...,
show_labels = "hidden",
table_names = vars,
.stats = NULL,
.formats = NULL,
.labels = NULL,
.indent_mods = NULL
)Arguments
- df
(
data.frame)
data set containing all analysis variables.- .var
(
string)
single variable name that is passed byrtableswhen requested by a statistics function.- n_events
(
integer)
number of events observed.- is_event
(
logical)TRUEif event,FALSEif time to event is censored.- control
-
(
list)
parameters for estimation details, specified by using the helper functioncontrol_incidence_rate(). Possible parameter options are:conf_level(proportion)
confidence level for the estimated incidence rate.conf_type(string)normal(default),normal_log,exact, orbyarfor confidence interval type.input_time_unit(string)day,week,month, oryear(default) indicating time unit for data input.num_pt_year(numeric)
time unit for desired output (in person-years).
- lyt
(
layout)
input layout where analyses will be added to.- vars
(
character)
variable names for the primary analysis variable to be iterated over.- ...
additional arguments for the lower level functions.
- show_labels
(
string)
label visibility: one of "default", "visible" and "hidden".- table_names
(
character)
this can be customized in case that the samevarsare analyzed multiple times, to avoid warnings fromrtables.- .stats
(
character)
statistics to select for the table.- .formats
(named
characterorlist)
formats for the statistics.- .labels
(named
character)
labels for the statistics (without indent).- .indent_mods
(named
integer)
indent modifiers for the labels. Defaults to 0, which corresponds to the unmodified default behavior. Can be negative.- person_years
(
numeric)
total person-years at risk.- alpha
(
numeric)
two-sided alpha-level for confidence interval.
Value
-
s_incidence_rate()returns the following statistics:person_years: Total person-years at risk.n_events: Total number of events observed.rate: Estimated incidence rate.rate_ci: Confidence interval for the incidence rate.
a_incidence_rate()returns the corresponding list with formattedrtables::CellValue().
estimate_incidence_rate()returns a layout object suitable for passing to further layouting functions, or tortables::build_table(). Adding this function to anrtablelayout will add formatted rows containing the statistics froms_incidence_rate()to the table layout.
Functions
s_incidence_rate(): Statistics function which estimates the incidence rate and the associated confidence interval.a_incidence_rate(): Formatted analysis function which is used asafuninestimate_incidence_rate().estimate_incidence_rate(): Layout-creating function which can take statistics function arguments and additional format arguments. This function is a wrapper forrtables::analyze().
See also
control_incidence_rate() and helper functions h_incidence_rate.
Examples
library(dplyr)
df <- data.frame(
USUBJID = as.character(seq(6)),
CNSR = c(0, 1, 1, 0, 0, 0),
AVAL = c(10.1, 20.4, 15.3, 20.8, 18.7, 23.4),
ARM = factor(c("A", "A", "A", "B", "B", "B"))
) %>%
mutate(is_event = CNSR == 0) %>%
mutate(n_events = as.integer(is_event))
basic_table() %>%
split_cols_by("ARM") %>%
add_colcounts() %>%
estimate_incidence_rate(
vars = "AVAL",
n_events = "n_events",
control = control_incidence_rate(
input_time_unit = "month",
num_pt_year = 100
)
) %>%
build_table(df)
#> A B
#> (N=3) (N=3)
#> —————————————————————————————————————————————————————————————————————
#> Total patient-years at risk 3.8 5.2
#> Number of adverse events observed 1 3
#> AE rate per 100 patient-years 26.20 57.23
#> 95% CI (-25.15, 77.55) (-7.53, 122.00)