如何为 R 中的分类数据生成自举置信区间?

How to generate bootstrapped confidence intervals for categorical data in R?

我正在尝试为 R 中的分类数据的正态分布数据构建简单的 95% 自举置信区间。常规 Bootstrap Confidence Intervals in Rboot.ci 似乎不适用于分类变量

df <- data.frame(
  dose = rep(c("10","20","30","40","50"),times= 10),
  count = rnorm(50, 1, 0.1)
)    

df$dose <- as.factor(df$dose)
df <- data.frame(
  dose = rep(c(10,20,30,40,50),times= 10)
)    
df$count <- rpois(50, df$dose)


df$dose <- factor(df$dose)
#I would consider if I can keep dose as numeric


fit <- glm(count ~ dose, data = df, family = "poisson")
summary(fit)

#bootstrap predictions
library(boot)
set.seed(42)
myboot <- boot(df, function(df, i) {
  fit <- glm(count ~ dose, data = df[i,])
  predict(fit, newdata = data.frame(dose = unique(df$dose)), type = "response")
}, 1e3)

lapply(seq_along(myboot$t0), function(i) boot.ci(myboot, index = i))
# [[1]]
# BOOTSTRAP CONFIDENCE INTERVAL CALCULATIONS
# Based on 1000 bootstrap replicates
# 
# CALL : 
#   boot.ci(boot.out = myboot, index = i)
# 
# Intervals : 
#   Level      Normal              Basic         
# 95%   ( 9.57, 13.93 )   ( 9.40, 13.90 )  
# 
# Level     Percentile            BCa          
# 95%   ( 9.50, 14.00 )   ( 9.54, 14.00 )  
# Calculations and Intervals on Original Scale
#
# ...