fsolt / dotwhisker

Dot-and-Whisker Plots of Regression Results
https://fsolt.org/dotwhisker/
Other
57 stars 10 forks source link

conflict with mixed.broom #88

Closed ThomasKraft closed 3 years ago

ThomasKraft commented 5 years ago

I used your dotwhisker and broom.mixed packages in R to create forest plots for a recent publication, and today a reader contacted me to notify me of some discrepancies between results reported in tables and forest plots. I was curious, so I went back to my code to check where the error occurred, and was surprised to find that my models were correct and that there were no basic errors. Despite feeding dwplot() a model with certain coefficients, the output plots indicated different coefficients.

To dig in deeper, I decided to check and make sure that dwplot() would work as expected using the example code in the dwplot() help file. So I ran the following:

m1 <- lm(mpg ~ wt + cyl + disp, data = mtcars) dwplot(m1, vline = geom_vline(xintercept = 0, colour = "grey50", linetype = 2)) + xlab("Coefficient")

At this point I realized that the coefficients being plotted do not match up to the model output! At this point I proceeded to restart R and run the test over again, but this time loading the broom package instead of the broom.mixed package. Indeed, this leads to the proper output. Expecting this to be an issue with the tidy() function in broom.mixed, I then checked:

tidy(m1)

Only to find that it does indeed produce the right coefficients in the table. So I'm guessing that the error is involved with dwplot, except that it seems to work fine unless broom.mixed is involved, so I'm left thoroughly confused!