0

I want to bootstrap a logistic model. The model with the whole dataset converges fine. However, the boot function chooses subsets that do not converge anymore. What can I do?

library(boot)
set.seed(2)
y <-  c(rep(0,10),rep(1,10))
x <- c(rnorm(10,2,1),rnorm(10,6,1))
dat = data.frame(x, y)

fit <- glm(y ~ x, quasibinomial(), data=dat)           # Model with all data workes fine

bs <- function(data, indices) {
  d <- data[indices,]
  fitboot <- glm(y ~ x, family = quasibinomial(), data=d)
  return(coef(fitboot)) 
} 

results <- boot(data=dat, statistic=bs, R=10)          # I get warnings

I get warnings that say:

1: glm.fit: algorithm did not converge 
2: glm.fit: algorithm did not converge 
3: glm.fit: algorithm did not converge 
4: glm.fit: algorithm did not converge 

This seems to be due to the subsets chosen.

Interestingly this subset works:

 fit <- glm(y ~ x, quasibinomial(), data=dat[1:13,]) 

But this does not:

 fit <- glm(y ~ x, quasibinomial(), data=dat[1:14,]) 

Why is that? And what can I do to bootstrap this model?

StupidWolf
  • 45,075
  • 17
  • 40
  • 72
Stefan
  • 13
  • 4

2 Answers2

2

The iteratively re-weighted least squares algorithm failed to converge in the default 25 iterations. The warning goes away if you increase the number of iterations as shown below:

fitboot <- glm(y ~ x, family = quasibinomial(), data=d,
               control=glm.control(maxit=50))
user25494
  • 1,289
  • 14
  • 27
  • Thanks!!! This works!!! You helped me a lot. I have spend the whole day at this and now it works. Thanks! – Stefan Nov 26 '15 at 12:16
0

Perhaps try to source the Wilcox package, that has several functions that allow bootstrapping. http://dornsife.usc.edu/labs/rwilcox/software/. Maybe it gives you other useful functions as well to use int he future.

Csaba Szabo
  • 103
  • 1
  • 2
  • 10