[Previously saved workspace restored] > # bootci.r December 2007 > # > # bootstrap confidence interval > # > # > # set up > # > # Exercise 8.13 -- least 3/2's estimator > # > # define function > g3o2 <- function(x) { + # derivative of function to be minimized + fp3o2 <- function (mu,u) { # derivative + fp3o2 <- sum( sign(u-mu)*sqrt(abs(u-mu)) ) } + # + # find root of derivative function + that2 <- uniroot(f=fp3o2, lower=min(x), upper=max(x), u=x ) + g3o2 <- that2$root } # root is statistic > # > # data > v <- c(225,215,209,175,163,135,153,125) > # > print(g3o2(v)) # compute statistic on data [1] 173.3705 > # First method -- create matrix and use apply > # data > set.seed(5151917) > Nboot <- 999 # DB suggests 99 rule > g3o2(v) # compute statistic on data > # > # > # sample from v -- how many? length(v)*Nboot, WITH replacement > # matrix so that each column is a bootstrap sample > V <- matrix(sample(v,length(v)*Nboot,replace=T),length(v),Nboot) > # compute statistic > vstar <- apply(V,2,g3o2) > # simple statistics > var(vstar) [1] 246.5115 > mean(vstar) [1] 173.4847 > # order statistics give CI limits > vStar <- sort(vstar) > # first 90% confidence interval > c(vStar[49],vStar[950]) [1] 150.5425 201.9542 > # then 95% > c(vStar[24],vStar[975]) [1] 142.2312 206.6722 > # > # done > rm(list=ls()) > q()