Skip to contents

The number of events over the person-time at risk, scaled to factor person-time units, with a confidence interval. This is the estimator behind the "rate" rows of tbl_rift(), exported so it can be called on its own or wrapped in a stat_fns function of tbl_custom_summary().

With d events over person-time T and z the normal quantile at conf.level, the limits are:

  • "normal-log" (the default): exp(log(d / T) ± z / sqrt(d)), the interval rifttable reports.

  • "normal": d / T ± z * sqrt(d) / T.

  • "exact": the Poisson interval of stats::poisson.test(), as ratio_summary() reports; only computed when d is a whole number.

Usage

rift_rate(
  data,
  event,
  time,
  factor = 1000,
  conf.level = 0.95,
  conf.type = c("normal-log", "normal", "exact"),
  na.rm = TRUE,
  ...
)

Arguments

data

(data.frame)
A data frame.

event

(string)
The column of event indicators (0/1 or logical) or event counts.

time

(string)
The column of person-time.

factor

(scalar numeric)
The rate is reported per this much person-time. Default is 1000.

conf.level

(scalar numeric)
Confidence level. Default is 0.95.

conf.type

(string)
One of "normal-log", "normal" and "exact".

na.rm

(scalar logical)
Whether rows with a missing event or time are dropped. Default is TRUE.

...

Not used. Accepted so that the function can be wrapped in functions that receive more arguments.

Value

A one-row data frame: events, time, estimate (the rate per factor person-time), conf.low, conf.high and method.

See also

Examples

# Example 1 ----------------------------------
# deaths per 1000 person-months
rift_rate(trial, event = "death", time = "ttdeath")
#>   events    time estimate conf.low conf.high                      method
#> 1     93 3941.58  23.5946 19.25516    28.912 Incidence rate (normal-log)

# Example 2 ----------------------------------
# per 100 person-months, by grade, in a custom summary table
trial |>
  tbl_custom_summary(
    include = grade,
    stat_fns = ~ function(data, ...) rift_rate(data, "death", "ttdeath", factor = 100),
    statistic = ~ "{estimate} ({conf.low}, {conf.high})",
    digits = ~ 1
  )