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.

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)

R4EPI/msfmisc documentation built on Feb. 9, 2023, 4:40 a.m.