如何在 R 中将 bootstrap CI 添加到此函数中

How to add bootstrap CI into this function in R

我想计算这两个估计值的 90% 置信区间 (Bootstrap)。 Harrell-Davis 无分布分位数估计器。我认为这个函数是非参数分位数的自举版本,它估计均值和标准差。现在我想知道如何计算 90% CI?

library(Hmisc)
x <- runif(100)
hdquantile(x, probs =  seq(0.025, 0.975,0.95), se=TRUE,names = TRUE, weights=FALSE)

如果设置 se=TRUE,hdquantile 函数会计算估计量并给出标准误差。要找到置信区间,您可以通过启动函数 bootstrap 它并通过 boot.ci

获得置信区间

代码

library(Hmisc)
x <- runif(100)
hdquantile(x, probs =  seq(0.025, 0.975,0.95), se=TRUE,names = TRUE, 
weights=FALSE)

为引导创建统计信息

library(boot)
hq <- function(x,i) {
hdquantile(x[i], probs =  seq(0.025, 0.975,0.95), se=TRUE,names = TRUE, 
weights=FALSE)
}
bootx <- boot(x,hq,1000)
boot.ci(bootx, conf = 0.90)