incidence_rate {tern}R Documentation

Incidence rate

Description

[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

estimate_incidence_rate(
  lyt,
  vars,
  n_events,
  control = control_incidence_rate(),
  na_str = default_na_str(),
  nested = TRUE,
  ...,
  show_labels = "hidden",
  table_names = vars,
  .stats = NULL,
  .formats = NULL,
  .labels = NULL,
  .indent_mods = NULL
)

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

Arguments

lyt

(PreDataTableLayouts)
layout that analyses will be added to.

vars

(character)
variable names for the primary analysis variable to be iterated over.

n_events

(integer(1))
number of events observed.

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.

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

  • num_pt_year (numeric)
    time unit for desired output (in person-years).

na_str

(string)
string used to replace all NA or empty values in the output.

nested

(flag)
whether this layout instruction should be applied within the existing layout structure _if possible (TRUE, the default) or as a new top-level element (FALSE). Ignored if it would nest a split. underneath analyses, which is not allowed.

...

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 the case that the same vars are analyzed multiple times, to avoid warnings from rtables.

.stats

(character)
statistics to select for the table. Run get_stats("estimate_incidence_rate") to see available statistics for this function.

.formats

(named character or list)
formats for the statistics. See Details in analyze_vars for more information on the "auto" setting.

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

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.

is_event

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

Value

Functions

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)


[Package tern version 0.9.5 Index]