Learn R Programming

Publish (version 2023.01.17)

formatCI: Formatting confidence intervals

Description

Format confidence intervals

Usage

formatCI(
  x,
  lower,
  upper,
  show.x = FALSE,
  handler = "sprintf",
  format = "[l;u]",
  degenerated = "asis",
  digits = 2,
  nsmall = digits,
  sep = "",
  reference.pos,
  reference.label = "",
  ...
)

Value

String vector with confidence intervals

Arguments

x

not used (for compatibility with format)

lower

Numeric vector of lower limits

upper

Numeric vector of upper limits

show.x

Logical. If TRUE show value of x in front of confidence interval.

handler

Function to format numeric values. Default is sprintf, also supported are format and prettyNum

format

Character string in which l will be replaced by the value of the lower limit (argument lower) and u by the value of the upper upper limit. For example, (l,u) yields confidence intervals in round parenthesis in which the upper and lower limits are comma separated. Default is [l;u].

degenerated

String to show when lower==upper. Default is '--'

digits

If handler format or prettyNum used format numeric vectors.

nsmall

If handler format or prettyNum used format numeric vectors.

sep

Field separator

reference.pos

Position of factor reference

reference.label

Label for factor reference

...

passed to handler

Author

Thomas A. Gerds <tag@biostat.ku.dk>

Details

The default format for confidence intervals is [lower; upper].

See Also

plot.ci ci.mean

Examples

Run this code

x=ci.mean(rnorm(10))
formatCI(lower=x[3],upper=x[4])
formatCI(lower=c(0.001,-2.8413),upper=c(1,3.0008884))
# change format
formatCI(lower=c(0.001,-2.8413),upper=c(1,3.0008884),format="(l, u)")
# show x
formatCI(x=x$mean,lower=x$lower,upper=x$upper,format="(l, u)",show.x=TRUE)

# change of handler function
l <- c(-0.0890139,0.0084736,144.898333,0.000000001)
u <- c(0.03911392,0.3784706,3338944.8821221,0.00001)
cbind(format=formatCI(lower=l,upper=u,format="[l;u)",digits=2,nsmall=2,handler="format"),
      prettyNum=formatCI(lower=l,upper=u,format="[l;u)",digits=2,nsmall=2,handler="prettyNum"),
      sprintf=formatCI(lower=l,upper=u,format="[l;u)",digits=2,nsmall=2,handler="sprintf"))

Run the code above in your browser using DataLab