QuantileCBs <- function(X,p=0.5,alpha=0.05) # Computation of exact (1 - alpha)-confidence bounds # for the p-quantile based on a sample X. # # Lutz Duembgen, September 10, 2009 { n <- length(X) Xs <- sort(X) # Compute Indices: # Indices for one- and two-sided upper bound: ui1 <- qbinom(p=1-alpha, size=n, prob=p) + 1 ui2 <- qbinom(p=1-alpha/2, size=n, prob=p) + 1 # Indices for one- and two-sided lower bound: li1 <- n - qbinom(p=1-alpha, size=n, prob=1-p) li2 <- n - qbinom(p=1-alpha/2, size=n, prob=1-p) # One-sided lower bound: if (li1 == 0) { lb1 <- -Inf } else { lb1 <- Xs[li1] } # One-sided upper bound: if (ui1 == n+1) { ub1 <- Inf } else { ub1 <- Xs[ui1] } # Confidence interval: if (li2 == 0) { lb2 <- -Inf } else { lb2 <- Xs[li2] } if (ui2 == n+1) { ub2 <- Inf } else { ub2 <- Xs[ui2] } return(list(lower.bound=lb1,upper.bound=ub1, confidence.interval=c(lb2,ub2))) }