0

Given the sample data dat below, I would appreciate any help to:

(1) check whether my approach below following boot's vignette to calculate bootstrap-based predictions from logistic regression is correct and help correct if there is any mistake in my approach.

(2) calculate bootstrap-based p-values comparing the observed probability and the predicted probability.

#my sample data:

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")

#doing bootstrap:

#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

#calculating bootstrap-based p-value comparing the observed probability(e.g., 0.45) and the predicted probabilities (based on the bootstrap algorithm):

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

Thanks in advance for any help. If there is anything that is not clear, please kindly let me know.

Krantz
  • 1,424
  • 1
  • 12
  • 31

0 Answers0