Learn R Programming

DescTools (version 0.99.6)

MedianCI: Confidence Interval for the Median

Description

Calculates the confidence interval for the median.

Usage

MedianCI(x, conf.level = 0.95, na.rm = FALSE, 
         type = c("pseudo", "exact", "boot"), R = 1000)

Arguments

x
a (non-empty) numeric vector of data values.
conf.level
confidence level of the interval
na.rm
logical. Should missing values be removed? Defaults to FALSE.
type
defining the type of interval that should be calculated. Default is "pseudo". See Details.
R
The number of bootstrap replicates. Usually this will be a single positive integer. See boot.ci for details.

Value

  • a numeric vector with 3 elements:
  • medianmedian
  • lwr.cilower bound of the confidence interval
  • upr.ciupper bound of the confidence interval

Details

The the confidence interval for the "pseudo median"" is extracted from wilcox.test (conf.int = TRUE). (Would you have expected it there?) The exact type is the way SAS is said to calculate the confidence interval. This is implemented in SignTest and is extracted from there. The boot confidence interval type is calculated by means of boot.ci with type "basic". Use sapply, resp.apply, to get the confidence intervals from a data.frame or from a matrix.

See Also

wilcox.test, MeanCI, median

Examples

Run this code
data(d.pizza)

MedianCI(d.pizza$price, na.rm=TRUE)
MedianCI(d.pizza$price, conf.level=0.99, na.rm=TRUE)

t(round(sapply(d.pizza[,c("delivery_min","temperature","price")], MedianCI, na.rm=TRUE), 3))


MedianCI(d.pizza$price, na.rm=TRUE, type="exact")
MedianCI(d.pizza$price, na.rm=TRUE, type="boot")

Run the code above in your browser using DataLab