formatCI: Formatting confidence intervals

View source: R/formatCI.R

formatCIR Documentation

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

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

Details

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

Value

String vector with confidence intervals

Author(s)

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

See Also

plot.ci ci.mean

Examples


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"))


Publish documentation built on Jan. 18, 2023, 1:08 a.m.