# Simple example of the percentile interval, based on the sample of 7 # observations of the Treated mice. (Data on p. 11 of E&T.) treatment <- c(94, 197, 16, 38, 99, 141, 23) set.seed(321) # I'll get a 90% percentile interval for the mean of the treatment dist'n. bss <- matrix( sample( treatment, 7*1999, replace=T ), nrow=1999 ) mean.rep <- apply( bss, 1, mean ) sorted.mean.rep <- sort( mean.rep ) # upper confidence bound: sorted.mean.rep[1900] # lower confidence bound: sorted.mean.rep[100] # Not too different from the interval (49.7, 126.7) given in Ch. 13 of E&T. # point estimate (sample mean): mean( treatment ) # Let's compare with a traditional t interval. t.result <- t.test( treatment, conf.level=0.90 ) t.result$conf.int # Let's further compare with a bootstrap-t interval. sd.rep <- apply( bss, 1, sd ) z.rep <- ( mean.rep - mean( treatment ) )/( sd.rep/sqrt(7) ) sorted.z.rep <- sort( z.rep ) # upper confidence bound: mean( treatment ) - sorted.z.rep[100]*sd( treatment )/sqrt( length( treatment ) ) # lower confidence bound: mean( treatment ) - sorted.z.rep[1900]*sd( treatment )/sqrt( length( treatment ) )