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