# Comparison of different confidence intervals for a distribution mean: # exponential distribution setting. set.seed(321) library(bootstrap) x <- rexp(25) # First, Student's t interval. t.result <- t.test( x, conf.level=0.95 ) t.result$conf.int # This is not the "gold standard" since the dist'n isn't normal. # Now the percentile interval. bss <- matrix( sample( x, 25*3999, replace=T ), nrow=3999 ) mean.rep <- apply( bss, 1, mean ) sorted.mean.rep <- sort( mean.rep ) # UCB for percentile interval: sorted.mean.rep[3900] # LCB for percentile interval: sorted.mean.rep[100] # Next, the BCA interval. bca.res <- bcanon( x, 3999, mean, alpha=c( 0.025, 0.975 ) ) bca.res$confpoint # The confidence bounds above should be close to those of the percentile # interval since there is no need for bias correction or acceleration # adjustments. Below I'll give the values of the bias correction and # acceleration computed by bcanon. bca.res$z0; bca.res$acc # Here is the ABC interval. resamp.mean <- function( p, x ) { sum( p*x )/sum( p ) } abc.res <- abcnon( x, resamp.mean, alpha=c( 0.025, 0.975 ) ) # LCB & UBC: abc.res$limits[1,2]; abc.res$limits[2,2] # Now, the bootstrap t interval (which makes use of some results obtained # in the percentile computations above. sd.rep <- apply( bss, 1, sd ) mean.x <- mean( x ) z.rep <- ( mean.rep - mean.x )/( sd.rep/5 ) sorted.z.rep <- sort( z.rep ) se.hat <- sd( x )/5 # UCB for bootstap t interval: mean.x - sorted.z.rep[100]*se.hat # LCB for bootstap t interval: mean.x - sorted.z.rep[3900]*se.hat # Finally, an exact interval based on the exponential dist'n parametric model # (obtained from a method covered in STAT 652 / CSI 672). numerator <- 2*sum(x) # UCB for exact interval: numerator/qchisq( 0.025, 50 ) # LCB for exact interval: numerator/qchisq( 0.975, 50 )