如何比较基于引导程序的预测概率和观察到的概率来计算p值

时间:2019-03-17 14:28:56

标签: r permutation p-value statistics-bootstrap hypothesis-test

鉴于下面的示例数据dat,对于以下帮助:

(1)检查我在启动vignette之后执行以下方法以从Logistic回归计算基于引导的预测的方法是否正确,如果我的方法有任何错误,请帮助纠正。

(2)计算     基于引导程序的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

#计算基于引导程序的p值,以比较观察到的概率(例如0.45)和预测的概率(基于引导程序算法):

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

在此先感谢您的帮助。如果有任何不清楚的地方,请告诉我。

0 个答案:

没有答案
相关问题