Learn R Programming

mosaic (version 0.4-1)

CIsim: Compute confidence intervals from (multiple) simulated data sets

Description

This function automates the calculation of coverage rates for exploring the robustness of confidence interval methods.

Usage

CIsim(n, samples = 100, rdist = rnorm, args = list(),
    estimand = 0, conf.level = 0.95, method = t.test,
    method.args = list(), interval = function(x) {
        do.call(method, c(list(x, conf.level = conf.level), method.args))$conf.int
    }, estimate = function(x) {
        do.call(method, c(list(x, conf.level = conf.level), method.args))$estimate
    }, verbose = TRUE)

Arguments

n
size of each sample
samples
number of samples to simulate
rdist
function used to draw random samples
args
arguments required by rdist
estimand
true value of the parameter being estimated
conf.level
confidence level for intervals
method
function used to compute intervals. Standard functions that produce an object of class htest can be used here.
method.args
arguments required by method
interval
a function that computes a confidence interval from data. Function should return a vector of length 2.
estimate
a function that computes an estimate from data
verbose
print summary to screen?

Value

  • A data frame with variables lower, upper, estimate, cover ('Yes' or 'No'), and sample is returned invisibly. See the examples for a way to use this to display the intervals graphically.

Examples

Run this code
CIsim(10,1000)    # 1000 95\% intervals using t.test; population is N(0,1)
CIsim(10,1000, rdist=rexp, estimand=1)    # this time population is Exp(1)
xYplot(Cbind(estimate,lower,upper) ~ sample,
  data=CIsim(10,100, rdist=rexp, estimand=1),
  par.settings=col.mosaic(), groups=cover)
ladd(panel.abline(h=1))

Run the code above in your browser using DataLab