Take numeric/character vectors of the estimate, and upper/lower confidence/credible intervals, round with trailing zeros and format into the required journal style.

pretty_ci(est, lci, uci, string = FALSE, sep = " to ", digits = 2,
  inline = FALSE, note = "95% CI ", replace_bracket = TRUE,
  percentage = FALSE)

Arguments

est

A numeric or character vector of estimates.

lci

A numeric or character vector of lower confidence/credible intervals.

uci

A numeric or character vector of upper confidence/credible intervals.

string

A logicial (defaults to FALSE) indicating if the estimates are being passed as a string to est (formatted as est, lci, uci) or seperately to est, lci and uci. Supports single estimates or a list/dataframe.

sep

A character vector indicating the seperator used between the upper and lower confidence/credible intervals. The default is ' to '.

digits

Integer indicating the number of decimal places to be used.

inline

Logical operator indicating whether an explanatory note is required.

note

A character vector indicating the explanatory note to be used.

replace_bracket

Logical, defaults to TRUE. Should the leading bracket be automatically be reinserted in front of the custom note supplied by note.

percentage

A logical (defaults to FALSE), which indicates whether the output should be treated as a percentage.

Value

The estimate with formated upper, and lower confidence/credible intervals as a character vector.

See also

pretty_round pretty_percentage

Examples

## Formating a single confidence interval pretty_ci(2, lci = 1, uci = 3)
#> [1] "2.00 (1.00 to 3.00)"
## Formating vectors of confidence intervals est <- c(0, 1, 100, 300, 21221, 403) lci <- c(-123, -0.2, 50, 100, 12321, 200) uci <- c(10, 2, 200, 400, 30122, 500) pretty_ci(est, lci = lci, uci = uci, sep = '-', digits = 1)
#> [1] "0.0 (-123.0-10.0)" "1.0 (-0.2-2.0)" #> [3] "100.0 (50.0-200.0)" "300.0 (100.0-400.0)" #> [5] "21221.0 (12321.0-30122.0)" "403.0 (200.0-500.0)"
## Use in a dplyr workflow library(dplyr)
#> #> Attaching package: ‘dplyr’
#> The following objects are masked from ‘package:stats’: #> #> filter, lag
#> The following objects are masked from ‘package:base’: #> #> intersect, setdiff, setequal, union
x <- data_frame(est = c(0,1), lci = c(0, 2), uci = c(1, 4)) x <- x %>% mutate(ci = est %>% pretty_ci(lci = lci, uci = uci, sep = ' by ', digits = 0)) ## Passing values as a single string est <- c(0, -1, 1) pretty_ci(est, string = TRUE)
#> [1] "0.00 (-1.00 to 1.00)"
est <- data.frame(est = c(1,2), lci = c(0, 1), uci = c(2, 3)) pretty_ci(est, string = TRUE)
#> [1] "1.00 (0.00 to 2.00)" "2.00 (1.00 to 3.00)"
est <- 98 lci <- 96 uci <- 99 pretty_ci(est, lci, uci, percentage = TRUE)
#> [1] "98.00% (96.00% to 99.00%)"