Learn R Programming

Publish (version 2017.10.24)

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,
  trim = TRUE, sep = "", ...)

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.

trim

Used to aligning resulting intervals. Also, if handler format or prettyNum used format numeric vectors .

sep

Field separator

...

passed to handler

Value

String vector with confidence intervals

Details

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

See Also

plot.ci ci.mean

Examples

Run this code
# NOT RUN {
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)

# if the first lower limit is shorter than the second (missing negative sign),
# then, option trim will make a difference:
formatCI(lower=c(0.001,-2.8413),upper=c(1,3.0008884),format="l--u",trim=FALSE)
formatCI(lower=c(0.001,-2.8413),upper=c(1,3.0008884),format="l--u",trim=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