CIsim: Simulated confidence intervals

Description Usage Arguments Details Value Author(s) See Also Examples

Description

Confidence intervals calculated from simulated data are stored in a data frame that allows further processing (including plotting).

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
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

sample size

samples

number of samples to simulate

rdist

random distribution function for generating random samples; defaults to rnorm

args

arguments for rdist

estimand

value of estimand

conf.level

level of confidence

method

function for computing a confidence interval and point estimate from data. method should return a list or structure containing named components conf.int and estimate (as in the default t.test) unless interval and estimate are supplied.

method.args

additional arguments for method.

interval

a function for computing a confidence interval from data

estimate

a function for computing the point estimate from data

verbose

should a report of percentage of simulated intervals that cover the estimand be printed to the screen?

Details

This function is design for flexibility and ease of use rather than for efficiency. The goal is to make it easy to estimate coverage rates for a wide range of confidence intervals and population distributions. The resulting data frame stores data in a manner suitable for plotting with xYplot() (see examples).

Value

A data frame with one row per sample and variables estimate (point estimate), lower (lower bound of confidence interval), upper (upper bound of confidence interval), cover (boolean indicating if estimand is in the interval), and sample (a counter, primarily useful for plotting)

Author(s)

Randall Pruim

See Also

xYplot in Hmisc.

Examples

1
2
3
4
CIsim(n=10,100) -> foo
if (require(Hmisc)) {
	xYplot(Cbind(estimate,lower,upper)~sample, foo,groups=cover, col=c('red','navy'),lwd=3,cap=0)
}

fastR documentation built on May 2, 2019, 5:53 p.m.