置信区间(r 中的自举)

问题描述 投票:0回答:0

我有一个包含 19 个值的向量。我想使用 bootstrap 方法计算每个值的置信区间。我使用以下代码:

library(boot)
alpha <- 0.9
B <- 1000
p_hat<-s$a     #vector with 19 values
intervals <- matrix(0, ncol = 2, nrow = length(p_hat))
for (i in 1:length(p_hat)) {
 my_function <- function(data, index) {
   return(mean(data[index]))`
 }
 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)

但是我得到错误:

Error in bca.ci(boot.out, conf, index[1L], L = L, t = t.o, t0 = t0.o, the calculated correspondence of 'w' is equal to infinity
r rstudio intervals confidence-interval statistics-bootstrap
© www.soinside.com 2019 - 2024. All rights reserved.