代码之家  ›  专栏  ›  技术社区  ›  Krantz

基于bootstrap的预测概率与观测概率的p值比较

  •  0
  • Krantz  · 技术社区  · 6 年前

    给定样本数据 dat 下面,我将感谢您的帮助:

    (1)检查下面的方法 vignette 从logistic回归计算基于bootstrap的预测是正确的,如果我的方法有任何错误,可以帮助纠正。

    (2)计算 基于bootstrap的p值比较观测概率和预测概率。

    #我的示例数据:

    ldose <- rep(0:5, 2)
    numdead <- c(1, 4, 9, 13, 18, 20, 0, 2, 6, 10, 12, 16)
    sex <- factor(rep(c("M", "F"), c(6, 6)))
    SF <- cbind(numdead, numalive = 20-numdead)
    dat<-data.frame(ldose, numdead, sex, SF)
    tibble::rowid_to_column(dat, "indices")
    
    new.data <- data.frame(ldose = 20, sex = "F")
    

    #执行引导:

    #Here I would appreciate any correction if something is not correct in my approach
    
    temp.out<-function(dat, indices, new.data) {
         d<-dat[indices, ] 
         fit1<- glm(SF ~ sex*ldose, family = binomial (link = logit), data = d)  
         return(predict(fit1, new.data, type="response"))
    }
    
    results <- boot::boot(dat, temp.out, 1000, sim = "permutation")
    
    boot::boot.ci(results, conf = 0.95, type = "all") #this fails
    
         Error in model.frame.default(formula = SF ~ sex * ldose, data = d, drop.unused.levels = TRUE) : 
          variable lengths differ (found for 'sex')
    
    boot::boot.ci(results, conf = c(0.90, 0.95), type = c("perc")) #this works
    

    #计算基于bootstrap的p值,比较观测概率(例如0.45)和预测概率(基于bootstrap算法):

    #Here I would appreciate any help to calculate the p-value
    

    提前谢谢你的帮助。如果有什么不清楚的地方,请告诉我。

    0 回复  |  直到 6 年前