Skip to contents

Builds a stat_fns function for tbl_custom_summary() that reports the ratio of two sums, e.g. an event rate over exposure time, with a Poisson confidence interval. The returned statistics are {num}, {denom}, {ratio}, {conf.low} and {conf.high}; the interval is only computed when the numerator sum is a whole number.

Usage

ratio_summary(numerator, denominator, na.rm = TRUE, conf.level = 0.95)

Arguments

numerator, denominator

(string)
Column names of the summed variables.

na.rm

(scalar logical)
Whether missing values are removed from the sums. Default is TRUE.

conf.level

(scalar numeric)
Confidence level of the interval. Default is 0.95.

Value

A function for the stat_fns argument of tbl_custom_summary().

See also

Other custom summaries: proportion_summary()

Examples

# Example 1 ----------------------------------
# responses per year of follow-up
trial |>
  tbl_custom_summary(
    include = grade,
    stat_fns = ~ratio_summary("response", "ttdeath"),
    statistic = ~"{ratio} [{conf.low}; {conf.high}] ({num}/{denom})",
    digits = ~c(3, 2, 2, 0, 0)
  )