1 |
x |
|
q |
|
alpha |
|
pr |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | ##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function (x, q = 0.5, alpha = 0.05, pr = FALSE)
{
if (pr) {
if (sum(duplicated(x) > 0))
print("Duplicate values detected; use hdpb")
}
n <- length(x)
ii <- floor(q * n + 0.5)
jj <- ii + 1
if (ii <= 0)
stop("Cannot compute a confidence interval for this q")
if (jj > n)
stop("Cannot compute a confidence interval for this q")
jjm <- jj - 1
iim <- ii - 1
cicov <- pbinom(jjm, n, q) - pbinom(iim, n, q)
while (cicov < 1 - alpha) {
iim <- max(iim - 1, 0)
jjm <- min(jjm + 1, n)
if (iim == 0 && jjm == n)
break
cicov <- pbinom(jjm, n, q) - pbinom(iim, n, q)
}
xsort <- sort(x)
low <- xsort[iim + 1]
hi <- xsort[jjm]
if (cicov < 1 - alpha) {
if (pr)
print("Warning: Desired probability coverage could not be achieved")
}
list(ci.low = low, ci.up = hi, ci.coverage = cicov)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.