Reputation: 45
I am trying to calculate bootstrap confidence intervals. Here is my code.
library(boot)
nboot <- 10000 # Number of simulations
alpha <- .01 # alpha level
n <- 1000 # sample size
bootThetaQuantile <- function(x,i) {
quantile(x[i], probs=.5)
}
raw <- rnorm(n,0, 1) # raw data
( theta.boot.median <- boot(raw, bootThetaQuantile, R=nboot) )
boot.ci(theta.boot.median, conf=(1-alpha)) #this causes no error
boot.ci(theta.boot.median, conf=(1-alpha), type = "percent") #this causes an error
The error message reads "Error in ci.out[[4L]] : subscript out of bounds". I am very confused by this because I am not sure why the call to boot.ci will cause an error when the previous line caused no error.
Upvotes: 3
Views: 1419
Reputation: 2995
That is because you have to use type = 'perc'
.
boot.ci(theta.boot.median, conf=(1-alpha), type = "perc")
Upvotes: 2