0

I want to do bootstrap of the division of the outputs of two regression models to get confidence intervals of the mean of the result of the operation.

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

#creating the function to be bootstrapped

out<-function(dat) {
     d<-data[indices, ] #allows boot to select sample
     fit1<- glm(SF ~ sex*ldose, family = binomial (link = log), start=c(-1,0,0,0))
     fit2<- glm(SF ~ sex*ldose, family = binomial (link = log), start=c(-1,0,0,0))
     coef1<-coef(fit1)
     numer<-exp(coef1[2])
     coef2<-coef(fit2)
     denom<-exp(coef2[2])
     resultX<-numer/denom
     return(mean(resultX))
}

#doing bootstrap

results <- boot(dat, out, 1000)

#error message

Error in statistic(data, original, ...) : unused argument (original)

Thanks in advance for any help.

Krantz
  • 1,424
  • 1
  • 12
  • 31
  • 1
    `out<-function(data, indices) { ...` There are many warnings from `glm` and both models are identical. – Roland Mar 08 '19 at 09:51
  • Thanks, @Roland. Yes - the models are identical just for simplicity. Let me test your answer. – Krantz Mar 08 '19 at 09:53
  • You should also study `help("boot")` where the necessary parameters of the function passed to `statistic` are described. – Roland Mar 08 '19 at 09:54
  • Yes. I am doing that. Thanks for the answer. It works but does not give any `se`, even when the models are different. Any thoughts? `#creating the function to be bootstrapped out<-function(data, indices) {... fit1<- glm(SF ~ sex*ldose, family = binomial (link = log), start=c(-1,0,0,0)) fit2<- glm(SF ~ sex + numdead + ldose, family = binomial (link = log), start=c(-1, 0, 0,0)) ... }#doing bootstrap results <- boot::boot(dat, out, 1000)` – Krantz Mar 08 '19 at 10:05
  • 1
    Maybe you should test with models that converge without problems. Look at `results$t`. Those are the bootstrap samples. – Roland Mar 08 '19 at 10:09
  • Thanks @Roland. I will keep exploring. – Krantz Mar 08 '19 at 10:18
  • 2
    I don't see `d` being passed to `glm()`. It should be the `data` argument. – user2554330 Mar 08 '19 at 10:50
  • Yes, it works without passing `d`. Otherwise, why would this work? Try this after running the function: `glm(SF ~ sex*ldose, family = binomial (link = log), start=c(-1,0,0,0)`. – Krantz Mar 08 '19 at 10:53
  • I think that is not behind my problem. Any thoughts? – Krantz Mar 08 '19 at 11:13
  • 1
    Yes, you should use the `data` argument in `glm`. It's using the variables from the global environment otherwise and that's the reason you get identical bootstrap estimates. – Roland Mar 08 '19 at 11:22
  • Yes. You are both right. Indeed after passing `d`I can get the `se`. Thank you for your insight. – Krantz Mar 08 '19 at 11:46

0 Answers0