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

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

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

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

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

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

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)
#> [1] "50.00% (CI 25.00--75.00)"

# If the data starts at a different column, specify a different number
fmt_pci_df(cfr[-1], 2, d = 1)
#> [1] "50.0% (CI 25.0--75.0)"

# It's also possible to provide numbers directly and remove the percent sign.
fmt_ci(pi, pi - runif(1), pi + runif(1), percent = FALSE)
#> [1] "3.14 (CI 2.81--3.58)"