1
$\begingroup$

I want to find bootstrapped CIs for the regression coefficients of the following Poisson regression:

m1p <- glm(Total_balls_chamber~AverageHumidity+Temp_offset+AverageHumidity:Temp_offset, family=poisson, data=Humid)

I have tried the following code:

    library(boot)

    bootReg=function(formula, data, i)
    {
        d <- data[i,]
        fit <- glm(formula,family=poisson, data = d)
        return(coef(fit))
        }

    bootResults=boot(statistic = bootReg, formula =Total_balls_chamber~AverageHumidity+Temp_offset+AverageHumidity:Temp_offset, data=Humid, R = 2000)

Which I have adapted from the example given from Andy Field's R text book (code here). This gives me the following error:

    Error in boot(statistic = bootReg, formula = Total_balls_chamber ~ AverageHumidity +  : 
      number of items to replace is not a multiple of replacement length

I have not been able to find any good examples on the net of how to bootstrap Poisson regressions. Does any one know of any good examples of boostrapping Poisson regressions, or could anyone point out what is wrong in my code?

I should also add, my sample size is only 16, and I wonder if the error is to do with my low sample size, rather than an error in the code.

$\endgroup$
5
  • 1
    $\begingroup$ I think this is because some of your predictors are factors, and when you bootstrap them, not all the bootstrap samples contain all levels of the predictors. So not quite small sample size, but small group (which is almost the same). $\endgroup$ Commented Dec 14, 2016 at 1:31
  • $\begingroup$ If the above comment is true you can solve the problem by converting the factors to dummies via a call to model.matrix $\endgroup$ Commented Dec 14, 2016 at 1:57
  • $\begingroup$ @JeremyMiles: I re ran the bootstrap omitting the factor from the analysis and it worked, so it seems my low sample sizes in each group (n=5-6, three groups) are the problem. $\endgroup$ Commented Dec 14, 2016 at 2:27
  • 1
    $\begingroup$ @generic_user: could you clarify what you mean by converting factors into dummies using the model.matrix function? I have set up the contrasts using the contr.treatment function, is that what you are referring to? $\endgroup$ Commented Dec 14, 2016 at 2:30
  • $\begingroup$ Possible duplicate of Absent categorical data levels in Bootstrap samples $\endgroup$ Commented Mar 30, 2019 at 8:54

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.