Skip to contents

[Stable]

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
)

h_incidence_rate_normal(person_years, n_events, alpha = 0.05)

h_incidence_rate_normal_log(person_years, n_events, alpha = 0.05)

h_incidence_rate_exact(person_years, n_events, alpha = 0.05)

h_incidence_rate_byar(person_years, n_events, alpha = 0.05)

h_incidence_rate(person_years, n_events, control = control_incidence_rate())

Arguments

df

(data frame)
data set containing all analysis variables.

.var

(string)
single variable name that is passed by rtables when requested by a statistics function.

n_events

(integer)
number of events observed.

is_event

(logical)
TRUE if event, FALSE if time to event is censored.

control

(list)
parameters for estimation details, specified by using the helper function control_incidence_rate(). Possible parameter options are:

  • conf_level: (proportion)
    confidence level for the estimated incidence rate.

  • conf_type: (string)
    normal (default), normal_log, exact, or byar for confidence interval type.

  • time_unit_input: (string)
    day, week, month, or year (default) indicating time unit for data input.

  • time_unit_output: (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

label visibility: one of "default", "visible" and "hidden".

table_names

(character)
this can be customized in case that the same vars are analyzed multiple times, to avoid warnings from rtables.

.stats

(character)
statistics to select for the table.

.formats

(named character or list)
formats for the statistics.

.labels

(named character)
labels for the statistics (without indent).

.indent_mods

(named integer)
indent modifiers for the labels.

person_years

(numeric)
total person-years at risk.

alpha

(numeric)
two-sided alpha-level for confidence interval.

Value

The statistics are:

  • 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

Functions

  • s_incidence_rate(): statistics function which estimates the incidence rate and the associated confidence interval.

  • a_incidence_rate(): Formatted Analysis function which can be further customized by calling rtables::make_afun() on it. It is used as afun in rtables::analyze().

  • estimate_incidence_rate(): layout creating function which adds analyze rows using the statistics function s_incidence_rate and desired format.

  • h_incidence_rate_normal(): helper function to estimate the incidence rate and associated confidence interval based on the normal approximation for the incidence rate. Unit is one person-year.

  • h_incidence_rate_normal_log(): helper function to estimate the incidence rate and associated confidence interval based on the normal approximation for the logarithm of the incidence rate. Unit is one person-year.

  • h_incidence_rate_exact(): helper function to estimate the incidence rate and associated exact confidence interval. Unit is one person-year.

  • h_incidence_rate_byar(): helper function to estimate the incidence rate and associated Byar's confidence interval. Unit is one person-year.

  • h_incidence_rate(): incidence_rate helper function to estimate the incidence rate and associated confidence interval.

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

# Internal function - s_incidence_rate
if (FALSE) {
s_incidence_rate(
  df,
  .var = "AVAL",
  n_events = "n_events",
  control = control_incidence_rate(
    time_unit_input = "month",
    time_unit_output = 100
  )
)
}

# Internal function - a_incidence_rate
if (FALSE) {
a_incidence_rate(
  df,
  .var = "AVAL",
  n_events = "n_events",
  control = control_incidence_rate(time_unit_input = "month", time_unit_output = 100)
)
}

basic_table() %>%
  split_cols_by("ARM") %>%
  add_colcounts() %>%
  estimate_incidence_rate(
    vars = "AVAL",
    n_events = "n_events",
    control = control_incidence_rate(
      time_unit_input = "month",
      time_unit_output = 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)

h_incidence_rate_normal(200, 2)
#> $rate
#> [1] 0.01
#> 
#> $rate_ci
#> [1] -0.003859038  0.023859038
#> 

h_incidence_rate_normal_log(200, 2)
#> $rate
#> [1] 0.01
#> 
#> $rate_ci
#> [1] 0.002500977 0.039984382
#> 

h_incidence_rate_exact(200, 2)
#> $rate
#> [1] 0.01
#> 
#> $rate_ci
#> [1] 0.001211046 0.036123438
#> 

h_incidence_rate_byar(200, 2)
#> $rate
#> [1] 0.01
#> 
#> $rate_ci
#> [1] 0.001994207 0.032054171
#> 

# Internal function - h_incidence_rate
if (FALSE) {
h_incidence_rate(200, 2)

h_incidence_rate(
  200,
  2,
  control_incidence_rate(
    conf_level = 0.9,
    conf_type = "normal_log",
    time_unit_output = 100
  )
)
}