Description Usage Arguments Value Examples
Computing the coverage of different confidence interval methods for quantiles by Monte Carlo integration.
1 2 3 4 5 6 7 8 9 | qci_coverage_one_sim(
qci_fun,
n,
rfunc = rnorm,
qfunc = qnorm,
p = 0.5,
conf.level = 0.95,
...
)
|
qci_fun |
Function which given n, p and conf.level computed a set of different confidence intervals. Should return a matrix of dimension 2 x (no. of methods) which contains the lower and upper bound of each confidence interval method. |
n |
Size of the sample to generate in the simulation |
rfunc |
Function for generating the samples |
qfunc |
Quantile function for computing the true quantile |
p |
The quantile of interest 0 <= p <= 1 |
conf.level |
conf.level * 100% two-sided confidence intervals are computed |
... |
Additional arguments passed to |
A vector of Booleans of length (no. methods) stating if each method contains the true value or not
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 | ##Function to compute different methods on same x.
quantile_confints <- function(x, p, conf.level, x_is_sorted=FALSE) {
if (!x_is_sorted) { x <- sort(x)}
##Compute the various confidence intervals as above
res <- data.frame(
nyblom_exact=quantileCI::quantile_confint_nyblom(x=x, p=p, conf.level=conf.level,
x_is_sorted=TRUE, interpolate=FALSE),
nyblom_interp=quantileCI::quantile_confint_nyblom(x=x, p=p, conf.level=conf.level,
x_is_sorted=TRUE, interpolate=TRUE),
boot=quantileCI::quantile_confint_boot(x, p=p, conf.level=conf.level, R=999)
)
if (p == 0.5) {
res$hs_interp = quantileCI::median_confint_hs(x=x, conf.level=conf.level,
x_is_sorted=TRUE, interpolate=TRUE)
}
return(res)
}
## One run of the simulation function
quantileCI::qci_coverage_one_sim(qci_fun=quantile_confints, n=100,p=0.5,conf.level=0.95)
## Several runs, calculate row means to get coverage by sampling
res <- sapply(1L:10L, function(i) {
quantileCI::qci_coverage_one_sim(qci_fun=quantile_confints, n=100,p=0.5,conf.level=0.95)
})
res
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.