### ekstra oppgave 8 fra Geir) estimer sd til thetaHat vha bootstrap: x <- c(1.2, 3.5, 4.7, 7.3, 8.6, 12.4, 13.8, 18.1) n <- length(x) trimed.mean <- function(x){ return(mean(sort(x)[3:(n-2)])) } theta.hat <- trimed.mean(x) NR <- c(25, 100, 200, 500, 1000, 2000, 3000, 4000, 5000, 10000) ###a) for(B in NR){ theta.star <- c() for(b in 1:B){ x.star <- sample(x, replace=T) #Sampling from F.hat theta.star[b] <- trimed.mean(x.star) #estimating theta based on bootstrap samples } sd.bootstrap <- sd(theta.star) #Calculating bootstrap estimates for sd print(paste("B=",B, " , sd=" , sd.bootstrap, sep="") ) } ###b) #Kjører forrige oppgave 10 ganger. #Ser at ved B=25 er ikke estimatet sd.bootstrap stabilt (det varierer mye). #Jo høyere B er, jo mer nøyaktig er estimatet sd.bootstrap. #Ved 1000 har vi en akseptabel nøyaktighet.