# from ch. 9 sim.samp<-function(nrep,n,DIST,...){ # simulates nrep samples from DIST of size n data <- matrix(DIST(n * nrep, ...), ncol = n, nrow = nrep) } set.seed(346) # sets the random number seed sim.samp(1000,15,rnorm)->z # 1000 N(0,1) samples, n=15 apply(z,1,mean)->out.m # mean for each sample trim20<-function(x){mean(x,.2)} # 20% trimmed mean function apply(z,1,trim20)->out.t20 # trim20 for each sample apply(z,1,median)->out.med # median for each sample # Save all 1000 blocks of 3 estimators in a data frame data.frame(mean=out.m,trim20=out.t20,median=out.med)->norm15 # from ch. 10 jack.var<-function(x, theta, ...){ call <- match.call() n <- length(x) u <- rep(0, n) for(i in 1:n) { u[i] <- theta(x[ - i], ...) } jack.var <- ((n - 1)/n) * sum((u - mean(u))^2) return(jack.var) } jack.se<-function(x, theta, ...){ call <- match.call() n <- length(x) u <- rep(0, n) for(i in 1:n) { u[i] <- theta(x[ - i], ...) } jack.se <- sqrt(((n - 1)/n) * sum((u - mean(u))^2)) return(jack.se) }