# data from Table 1.2.1 tab121 <- c(7, 11, 15, 16, 20, 22, 24, 25, 29, 33, 34, 37, 41, 42, 49, 57, 66, 71, 84, 90) # a function to calculate confidence intervals for percentiles # using the normal approximation to the binomial distribution # Note that both p and alpha are numbers between 0 and 1 cipercent <- function(y,p,alpha) { n <- length(y) a <- n*p - qnorm(1 -alpha/2)*sqrt(n*p*(1-p)) b <- 1 +n*p + qnorm(1 -alpha/2)*sqrt(n*p*(1-p)) ar <- round(a) ; br <- round(b) lower <- y[order(y)[ar]] upper <- y[order(y)[br]] # print(c(n,a,b,ar,br,lower,upper)) c(lower,upper) } # this gives the same results as the example in the text cipercent(tab121,.25,.10)