# quantileCI: Confidence Intervals for Quantiles In MKmisc: Miscellaneous Functions from M. Kohl

## Description

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

## Usage

 ```1 2 3 4 5 6``` ```quantileCI(x, prob = 0.5, conf.level = 0.95, method = "exact", minLength = FALSE, na.rm = FALSE) medianCI(x, conf.level = 0.95, method = "exact", minLength = FALSE, na.rm = FALSE) madCI(x, conf.level = 0.95, method = "exact", minLength = FALSE, na.rm = FALSE, constant = 1.4826) ```

## Arguments

 `x` numeric data vector `prob` quantile `conf.level` confidence level `method` character string specifing which method to use; see details. `minLength` logical, see details `na.rm` logical, remove `NA` values. `constant` scale factor (see `mad`).

## 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`, then a matrix of confidence intervals is returned. If `minLength = TRUE`, an exact confidence interval with minimum length 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).

## 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.

`binom.test`, `binconf`

## Examples

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19``` ```## To get a non-trivial exact confidence interval for the median ## one needs at least 6 observations set.seed(123) x <- rnorm(8) ## exact confidence interval not unique medianCI(x) madCI(x) ## minimum length exact confidence interval medianCI(x, minLength = TRUE) madCI(x, minLength = TRUE) ## asymptotic confidence interval medianCI(x, method = "asymptotic") madCI(x, method = "asymptotic") ## confidence interval for quantiles quantileCI(x, prob = 0.4) quantileCI(x, prob = 0.6) ```

### Example output

```\$call
medianCI(x = x)

\$estimate
50%
0.09989806

\$CI
[,1]     [,2]
[1,] -1.2650612 1.558708
[2,] -0.5604756 1.715065
attr(,"(exact) confidence level")
 0.9609375

\$call

\$estimate
50%
0.7571578

\$CI
[,1]     [,2]
[1,] 0.04357313 2.162832
[2,] 0.04357313 2.394646
attr(,"(exact) confidence level")
 0.9609375

\$call
medianCI(x = x, minLength = TRUE)

\$estimate
50%
0.09989806

\$CI
 -0.5604756  1.7150650
attr(,"(exact) confidence level")
 0.9609375

\$call
madCI(x = x, minLength = TRUE)

\$estimate
50%
0.7571578

\$CI
 0.04357313 2.16283208
attr(,"(exact) confidence level")
 0.9609375

\$call
medianCI(x = x, method = "asymptotic")

\$estimate
50%
0.09989806

\$CI
 -1.265061  1.558708
attr(,"(asymptotic) confidence level")
 0.95

\$call
madCI(x = x, method = "asymptotic")

\$estimate
50%
0.7571578

\$CI
 0.04357313 2.16283208
attr(,"(asymptotic) confidence level")
 0.95

\$call
quantileCI(x = x, prob = 0.4)

\$estimate
40%
0.01037122

\$CI
 -1.265061  1.558708
attr(,"(exact) confidence level")
 0.9746842

\$call
quantileCI(x = x, prob = 0.6)

\$estimate
60%
0.1956134

\$CI
 -0.5604756  1.7150650
attr(,"(exact) confidence level")
 0.9746842
```

MKmisc documentation built on Aug. 8, 2021, 5:06 p.m.