> # jacktest.r December 2007 > # > # compare speeds for jackknife > # > # First method -- create matrix and use apply > # data > set.seed(5151917) > N <- 1000 > v <- -log(runif(N)) # generate exponential RVs > mean(v,trim=.2) # compute statistic on data [1] 0.775349 > # > proc.time() # read clock before execution [1] 0.93 0.11 1.04 0.00 0.00 > V <- matrix(v,N-1,N) > # compute statistic > vps <- apply(V,2,mean,trim=.2) > proc.time() # read clock after execution [1] 2.30 0.18 2.47 0.00 0.00 > var(vps) [1] 8.235568e-07 > mean(vps) [1] 0.7756938 > # > # Second method -- using loop > proc.time() # read clock before execution [1] 2.30 0.18 2.47 0.00 0.00 > vps <- rep(0,N) > for(i in(1:N)){ vps[i]<-mean(v[-i],trim=.2) } > proc.time() # read clock after execution [1] 3.19 0.18 3.37 0.00 0.00 > mean(vps) [1] 0.7756938 > var(vps) [1] 8.235568e-07 > # done > rm(list=ls()) > q()