5

I would like to calculate Wald confidence intervals of the coefficients of a glm on a somewhat large data set, and use broom for a tidy output.

mydata <- data.frame(y = rbinom(1e5,1,0.8), 
                 x1 = rnorm(1e5), 
                 x2 = rnorm(1e5))
glm.1 <- glm(y ~ x1 + x2, data = mydata, family = "binomial")

Using broom::tidy takes a lot of time on large data, since it uses confint.glm, which calculates the confidence intervals based on the profiled log-likelihood function.

tidy(glm.1, conf.int = TRUE) # can take literally hours
bebru
  • 151
  • 9

1 Answers1

7

confint and confint.glm respectively do not take an argument for the method used to calculate the confidence intervals. If you want to use another method, you need to use a different function, e.g. confint.default for Wald.

broom::tidy in turn does not have an argument for the function used (or did I miss something?), it always calls confint.glm for glm.

To calculate confidence intervals with a different function, broom has confint_tidy, where you can specify the function you want to use:

confint_tidy(glm.1, func = stats::confint.default)

Put this together with the estimates:

cbind(tidy(glm.1), confint_tidy(glm.1, func = stats::confint.default))
bebru
  • 151
  • 9
  • 3
    Unfortunately this function is now deprecated and will be removed from broom. There was some discussion about including an argument in the tidy function for confidence interval methods but I dont see anything as of now. – Koray Mar 24 '21 at 22:35
  • 1
    Thanks for the info @Koray. Adding the link to the respective Github issue: [broom issue #989](https://github.com/tidymodels/broom/issues/989) – bebru Mar 26 '21 at 09:11