Quantile Confidence Interval
Menu location: Analysis_Nonparametric_Quantile Confidence Interval.
This function provides a confidence interval for any quantile or (per)centile.
As with all nonparametric confidence intervals, the exact confidence level is not always attainable but the level which is exact to the interval constructed is displayed (Conover, 1999; Gardner and Altman, 1989).
Assumptions:
- random sample
- measurement scale is at least ordinal
A presentation of medians and their confidence intervals is often more meaningful than the time honoured (abused) tradition of presenting means and standard deviations. Researchers sometimes quote means and their confidence intervals in situations where a median with confidence interval would be more appropriate (e.g. when outliers have a biasing effect on the mean but there is insufficient evidence to exclude them from the analysis). A box and whisker plot is a useful accompaniment to this function.
Technical Validation
For sample sizes greater than 200 an approximation to the binomial distribution is used otherwise the critical values of the binomial distribution used in this calculation are found by an exact method (Conover, 1999). If the conservative option is not selected or the sample size is greater than 200 then for a c*100% confidence interval the binomial quantiles closest to a cumulative probability of (1-c)/2 and 1-(1-c)/2 are used. If the conservative option is selected and the sample size is not greater than 200 then for a c*100% confidence interval the binomial quantiles closest to and less than or equal to a cumulative probability of (1-c)/2, and closest to and greater than or equal to a cumulative probability of 1-(1-c)/2 are used. Note that the conservative interval calculates each side, not just the overall interval, on a conservative basis.
Example
From Conover (1999, p. 145).
Test workbook (Nonparametric worksheet: Tubes).
The following represent times to failure in hours for a set of pentode radio valves.
| Tubes |
| 46.9 |
| 47.2 |
| 49.1 |
| 56.5 |
| 56.8 |
| 59.2 |
| 59.9 |
| 63.2 |
| 63.3 |
| 63.4 |
| 63.7 |
| 64.1 |
| 67.1 |
| 67.7 |
| 73.3 |
| 78.5 |
To analyse these data in StatsDirect you must first enter them into a workbook column and label it appropriately. Alternatively, open the test workbook using the file open function of the file menu. Then select Quantile Confidence Interval from the Nonparametric section of the analysis menu. Select the column marked "Tubes" when prompted for data. Choose 90% as the confidence level. Then enter 0.75 to specify that the quantile you want is the upper quartile or 75th percentile.
For this example:
Quantile (0.75) = 66.35
Approximate 90% CI (non-conservative) = 63.3 to 73.3
Exact confidence level = 90.93936%
Approximate 90% CI (conservative) = 63.3 to 78.5
Exact confidence level = 96.284745%
We may conclude with 91% confidence that the population value of the upper quartile lies between 63.3 and 73.3 hours.
R code
This R code reproduces the example above. It needs no packages and was checked with R 4.6.1. Paste it into R, or save it as a script and run it.
# Quantile confidence interval: the StatsDirect help example (Conover 1999,
# p. 145) in R
tubes <- c(46.9, 47.2, 49.1, 56.5, 56.8, 59.2, 59.9, 63.2, 63.3, 63.4, 63.7, 64.1,
67.1, 67.7, 73.3, 78.5)
p <- 0.75 # the upper quartile
conf <- 0.90
x <- sort(tubes)
n <- length(x)
# The quantile. StatsDirect takes the p(n + 1)th ordered value, interpolating
# between neighbours. That is type 6 in R, whose default is type 7 (64.85 here).
cat("Quantile (", p, ") = ", quantile(tubes, p, type = 6), "\n", sep = "")
# R has no standard function for this interval. The limits are ordered values.
# The number of observations below the population quantile is binomial(n, p), so
# cum[q + 1] is the probability that at most q of them are below it, and the
# interval from the (lo + 1)th to the (hi + 1)th ordered value covers the
# quantile with probability cum[hi + 1] - cum[lo + 1].
cum <- pbinom(0:n, n, p)
tail <- (1 - conf) / 2
show <- function(lo, hi, label) {
cat(sprintf("Approximate %g%% CI (%s) = %g to %g\n", 100 * conf, label,
x[lo + 1], x[hi + 1]))
cat("Exact confidence level = ",
format(round(100 * (cum[hi + 1] - cum[lo + 1]), 6), digits = 10), "%\n",
sep = "")
}
# Non-conservative: the probability in each tail is as close as it can be to
# (1 - conf) / 2
show(which.min(abs(cum - tail)) - 1, which.min(abs(cum - (1 - tail))) - 1,
"non-conservative")
# Conservative: no more than (1 - conf) / 2 in each tail. With a small sample, or
# a quantile near 0 or 1, no ordered value may be far enough out: StatsDirect
# then uses the smallest or largest observation and marks the limit.
stopifnot(any(cum <= tail), any(cum >= 1 - tail))
show(max(which(cum <= tail)) - 1, min(which(cum >= 1 - tail)) - 1, "conservative")