简体   繁体   中英

How to change ci_method to "wald" in a logistic regression in R

I need to run a logistic regression on a dataset with approximately 1,000,000 data points. I ran a model

logit_results <<- glm(y ~ p1 + p2 + p3,
                      data = df,family="binomial", 
                      na.action = "na.exclude")

I want to visualise the results using the plot_model() function

library(sjPlot)
plot_x <- plot_model(logit_results,vline.color = "#1EA891",sort.est = TRUE,title="Graph") 

This is taking forever to run (I've been waiting for about an hour, and it hasn't finished). I get a message Profiled confidence intervals may take longer time to compute. Use `ci_method="wald"` for faster computation of CIs. Profiled confidence intervals may take longer time to compute. Use `ci_method="wald"` for faster computation of CIs. However, I don't know where to change the ci_method, as neither the glm() or plot_model() use ci_method .

Anyone knows how might I change the ci_method to "wald"?

This message comes from the parameters package, which is a dependency from sjPlot package. If we look at the source code from tidy_model in sjPlot (I looked it up from rdrr.io but I think we can do something like sjPlot:::tidy_model ), then we would find the following code:

if (is.null(p.val)) {
      if (inherits(model, c("glm", "polr"))) {
        p.val <- "profile"
      } else {
        p.val <- "wald"
      }
    }

This means if p.val is not specified and the model comes from glm or polr, then p.val is profile, which later on translates to ci_method="profile", else ci_method would be "wald".

So this becomes pretty obvious, all we have to do is to specify p.val="wald" :

plot_x <- plot_model(logit_results,vline.color = "#1EA891",
      sort.est = TRUE,title="Graph",p.val="wald") 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM