Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • What Is the Best Way to Visualize My Logistic Regression Model?

    Good evening, everyone.

    In my field (Health Sciences), it is common to use logistic regression models to calculate probabilities. These models assign a logit value based on typically categoric variables. After many years of building these kinds of models for physicians, I’ve realized two things: 1) many of them don’t know that such models are possible (obtaining a probability from sum terms) and are unfamiliar with them; and 2) those who get excited about it expect to obtain a probability value, not a logit, which can be difficult to understand at a first sight.

    For several years, I’ve been thinking about the best way to visualize and graph these model equations so that, at a glance, people with little statistical knowledge can understand how the independent variables affect the probability, as well as the confidence intervals of that prediction. A couple of weeks ago, I gave it a try using Stata and programmed an .ado file that allows you to obtain the type of graph shown in the figure. However, I’m not sure it meets its purpose, so if anyone is interested, I would appreciate critical feedback on my graph to know how I could improve it and make it more understandable.

    Thank you to the forum, as always.
    Click image for larger version

Name:	Graph.jpg
Views:	1
Size:	107.8 KB
ID:	1765885

  • #2
    I like it, Emilio! My assumption from looking at this graph is that your model has a three-way interaction. Did you use Stata's margins command to produce the probabilities? It also has a graphing option (marginsplot), but it would be quite a bit of work to create a graph like this using marginsplot. Another route to make use of margins is to use the undocumented saving option with margins to create a dataset based on the estimated probabilities. That could be used to produce a graph like this.
    Last edited by Erik Ruzek; 16 Oct 2024, 17:43. Reason: Grammatical fixes

    Comment


    • #3
      Thank you for your approval, Erik Ruzek . Regarding your question: I construct the probabilities using the logit command. With the coefficients provided by this command, I build an equation of the form: logit(p) = Constant + Coef1(var1) + Coef2(var2) + … + Coef_n(var_n). Then, I calculate the logits for each combination of categories of variables and, from the logits, the probability. The confidence interval margins are constructed in the same way, but instead of using the coefficients, I use the lower or upper bound of the confidence interval of each coefficient.

      The result… wasn’t as aesthetically pleasing as I had imagined until I realized that the graph would look nicer if I sorted the variables so that the ones with the largest coefficients were on the left, and the smaller ones on the right. Additionally, I noticed that if I reversed the order of the variable categories when the coefficient was negative, the confidence intervals would be displayed in a smooth and friendly manner, from the top left to the bottom right. I also added a color scheme to make it more visually appealing.

      In the past few days, I have been working on creating an .ado file to automate the creation of these graphs and maybe upload it to SSC. That’s where I am right now. I still need to debug some errors, improve the dialog box, and write the help file. And, of course, get feedback from the forum.
      Click image for larger version

Name:	Graph.jpg
Views:	1
Size:	53.9 KB
ID:	1766113

      Comment


      • #4
        Good morning, everyone. I’ve been working on this type of graph, and it’s now available through SSC:

        ssc install logitgraph
        I hope it will be useful to someone.

        Click image for larger version

Name:	cover.jpeg
Views:	1
Size:	149.9 KB
ID:	1766847

        Comment

        Working...
        X