I have a vector of 19 values. I want to calculate confidence intervals for each value using the bootstrap method. I use the following code:
library(boot)
alpha <- 0.9
B <- 1000
p_hat<-s$a #vector with 19 values
intervals <- matrix(0, ncol = 2, nrow = length(p_hat))
my_function <- function(data, index) {
return(median(data[index]))
for (i in 1:length(p_hat)) {
boot_samples <- boot(p_hat[i], my_function, R = B)
intervals[i,] <- boot.ci(boot_samples, type = "bca", conf = .9)
}
}
results <- data.frame(p_hat, intervals)
print(results)
I get 0 instead of confidence intervals
Data
This is the vector posted in comment.
p_hat <- c(0, 0, 6.70881, 14.16335, 26.08988, 41.33073, 57.23204,
74.02023, 88.54585, 95.48473, 98.97599, 99.90797,
99.94741, 100, 100, 100, 100, 100, 100)