fmt_ci: Helper to format confidence interval for text

View source: R/inline_fun.R

fmt_ciR Documentation

Helper to format confidence interval for text

Description

This function is mainly used for placing in the text fields of Rmarkdown reports. You can use it by writing it in something like this: The CFR for Bamako is `r fmt_ci_df(case_fatality_rate(10, 50))` which will render like this: "The CFR for Bamako is 20.00% (CI 11.24-33.04)"

Usage

fmt_ci(
  e = numeric(),
  l = numeric(),
  u = numeric(),
  digits = 2,
  percent = TRUE,
  separator = "-"
)

fmt_pci(
  e = numeric(),
  l = numeric(),
  u = numeric(),
  digits = 2,
  percent = TRUE,
  separator = "-"
)

fmt_pci_df(
  x,
  e = 3,
  l = e + 1,
  u = e + 2,
  digits = 2,
  percent = TRUE,
  separator = "-"
)

fmt_ci_df(
  x,
  e = 3,
  l = e + 1,
  u = e + 2,
  digits = 2,
  percent = TRUE,
  separator = "-"
)

Arguments

e

the column of the estimate (defaults to the third column). Otherwise, a number

l

the column of the lower bound (defaults to the fourth column). Otherwise, a number

u

the column of the upper bound (defaults to the fifth column), otherwise, a number

digits

the number of digits to show

percent

if TRUE (default), converts the number to percent, otherwise it's treated as a raw value

separator

what to separate lower and upper confidence intervals with, default is "-"

x

a data frame

Value

a text string in the format of "e\

Examples


cfr <- data.frame(x = 1, y = 2, est = 0.5, lower = 0.25, upper = 0.75)
fmt_pci_df(cfr)

# If the data starts at a different column, specify a different number
fmt_pci_df(cfr[-1], 2, d = 1)

# It's also possible to provide numbers directly and remove the percent sign.
fmt_ci(pi, pi - runif(1), pi + runif(1), percent = FALSE)

epikit documentation built on Feb. 16, 2023, 7:42 p.m.