quantileCI: Confidence Intervals for Quantiles

View source: R/quantileCI.R

quantileCIR Documentation

Confidence Intervals for Quantiles

Description

These functions can be used to compute confidence intervals for quantiles (including median and MAD).

Usage

quantileCI(x, prob = 0.5, conf.level = 0.95, method = "exact",
           R = 9999, bootci.type = c("norm", "basic", "perc", "bca"), 
           na.rm = FALSE, alternative = c("two.sided", "less", "greater"), ...)
medianCI(x, conf.level = 0.95, method = "exact",
         R = 9999, bootci.type = c("norm", "basic", "perc", "bca"), 
         na.rm = FALSE, alternative = c("two.sided", "less", "greater"), ...)
madCI(x, conf.level = 0.95, method = "exact", 
      R = 9999, bootci.type = c("norm", "basic", "perc", "bca"), 
      na.rm = FALSE, constant = 1.4826, 
      alternative = c("two.sided", "less", "greater"), ...)

Arguments

x

numeric data vector

prob

quantile

conf.level

confidence level

method

character string specifing which method to use; see details.

R

number of bootstrap replicates.

bootci.type

type of bootstrap interval; see boot.ci.

na.rm

logical, remove NA values.

constant

scale factor (see mad).

alternative

a character string specifying one- or two-sided confidence intervals. Must be one of "two.sided" (default), "greater" or "less" (one-sided intervals). You can specify just the initial letter.

...

further arguments passed to function boot, e.g. for parallel computing.

Details

The exact confidence interval (method = "exact") is computed using binomial probabilities; see Section 6.8.1 in Sachs and Hedderich (2009). If the result is not unique, i.e. there is more than one interval with coverage proability closest to conf.level, the shortest confidence interval is returned.

The asymptotic confidence interval (method = "asymptotic") is based on the normal approximation of the binomial distribution; see Section 6.8.1 in Sachs and Hedderich (2009).

In case of discrete data, there are alternative bootstrap approaches that might give better results; see Jentsch and Leucht (2016).

Since madCI is computed as the median confidence interval of the absolut deviations from the sample median and ignores the variablity of the sample median, the exact and asymptotic confidence intervals might be too short. We recommend to use bootstrap confidence intervals.

Value

A list with components

estimate

the sample quantile.

CI

a confidence interval for the sample quantile.

Author(s)

Matthias Kohl Matthias.Kohl@stamats.de

References

L. Sachs and J. Hedderich (2009). Angewandte Statistik. Springer.

C. Jentsch and A. Leucht (2016). Bootstrapping sample quantiles of discrete data. Ann Inst Stat Math, 68: 491-539.

See Also

quantile

Examples

## To get a non-trivial exact confidence interval for the median
## one needs at least 6 observations
x <- rnorm(5)
medianCI(x)

## asymptotic confidence interval
medianCI(x, method = "asymptotic")
madCI(x, method = "asymptotic")

## bootstrap confidence interval
x <- rnorm(50)
medianCI(x)
medianCI(x, method = "asymptotic")
## (R = 999 to reduce computation time for R checks)
medianCI(x, method = "boot", R = 999)

madCI(x)
madCI(x, method = "asymptotic")
## (R = 999 to reduce computation time for R checks)
madCI(x, method = "boot", R = 999)

## confidence interval for quantiles
quantileCI(x, prob = 0.25)
quantileCI(x, prob = 0.25, method = "asymptotic")

quantileCI(x, prob = 0.75)
## (R = 999 to reduce computation time for R checks)
quantileCI(x, prob = 0.75, method = "boot", R = 999)

## one-sided
quantileCI(x, prob = 0.75, alternative = "greater")
medianCI(x, alternative = "less", method = "asymptotic")
madCI(x, alternative = "greater", method = "boot", R = 999)


## parallel computing for bootstrap
medianCI(x, method = "boot", R = 9999, parallel = "multicore", 
         ncpus = 2)


stamats/MKinfer documentation built on April 10, 2024, 3:33 p.m.