The function rounds the estimate, lower and upper confidence interval to the same magnitude. The magnitude shows the width of the confidence interval with two significant digits.

format_ci(estimate, se, lcl, ucl, interval = 0.95, link = c("identity",
  "log", "logit"), max_digit = 4, percent = FALSE, sign = FALSE)

Arguments

estimate

The estimate in the link scale.

se

The standard error in the link scale. If missing, you must provide values for lcl and ucl.

lcl

The lower confidence limit. Ignored when se is given.

ucl

The upper confidence limit. Ignored when se is given.

interval

The coverage of the confidence interval. Only used when se is given. Defaults to 0.95 (95%).

link

The transformation of estimate, se, lcl and ucl. The appropriate backtransformation is applied before formatting.

max_digit

The maximum number of significant digits to display. Defaults to 4.

percent

Display the interval as a percentage (= muliply by 100 and append %). Defaults to FALSE.

sign

Always add the sign to the text. (e.g. +1 instead of 1). Defaults to FALSE.

Examples

format_ci(0.512345, 1)
#> [1] "0.5 (-1.4; 2.5)"
format_ci(0.512345, 1, interval = 0.9)
#> [1] "0.5 (-1.1; 2.2)"
format_ci(0.512345, 1, link = "log")
#> [1] "1.7 (0.2; 11.8)"
format_ci(0.512345, 1, link = "logit")
#> [1] "0.63 (0.19; 0.92)"
format_ci(0.512345, 10)
#> [1] "1 (-19; 20)"
format_ci(0.512345, 0.1)
#> [1] "0.51 (0.32; 0.71)"
format_ci(0.512345, 0.01)
#> [1] "0.512 (0.493; 0.532)"
format_ci(0.512345, 0.001)
#> [1] "0.5123 (0.5104; 0.5143)"
format_ci(0.512345, 0.0001)
#> [1] "0.5123 (0.5121; 0.5125)"
format_ci(0.512345, 0.00001)
#> [1] "0.5123 (0.5123; 0.5124)"
format_ci(0.512345, 0.00001, max_digit = 10)
#> [1] "0.512345 (0.512325; 0.512365)"
format_ci(0.512345, 0.5)
#> [1] "0.51 (-0.47; 1.49)"
format_ci(-0.1, lcl = -0.1999, ucl = 0.1234)
#> [1] "-0.100 (-0.200; 0.123)"
format_ci(-0.1, lcl = -0.1999, ucl = 0.1234, percent = TRUE)
#> [1] "-10.0% (-20.0%; 12.3%)"
format_ci(-0.1, lcl = -0.1999, ucl = 0.1234, sign = TRUE)
#> [1] "-0.100 (-0.200; +0.123)"
format_ci(-0.1, lcl = -0.1999, ucl = 0.1234, percent = TRUE, sign = TRUE)
#> [1] "-10.0% (-20.0%; +12.3%)"
format_ci(0.512345e-6, 1e-6)
#> [1] "0.0000005 (-0.0000014; 0.0000025)"
format_ci(0.512345e-7, 1e-7)
#> [1] "5e-08 (-1.4e-07; 2.5e-07)"
format_ci(0.512345e-7, 1e-8)
#> [1] "5.1e-08 (3.2e-08; 7.1e-08)"
format_ci(0.512345e-7, 1e-9)
#> [1] "5.12e-08 (4.93e-08; 5.32e-08)"