larmarange / broom.helpers

A set of functions to facilitate manipulation of tibbles produced by broom
https://larmarange.github.io/broom.helpers/
GNU General Public License v3.0
21 stars 8 forks source link

beta regression is not supported yet #234

Closed yuryzablotski closed 1 year ago

yuryzablotski commented 1 year ago

Hi guys, beta regression can't be processed with tbl_regression(). Would be nice if it worked:

d <- mtcars %>% mutate(mpg = mpg/100, cyl = factor(cyl))

library(betareg) m <- betareg(mpg ~ cyl, data = d)

plot_model(m, type = "pred")

library(emmeans) emmeans(m, pairwise ~ cyl, type = "response")

library(gtsummary) tbl_regression(m, add_pairwise_contrasts = T)

The error message on my computer is:

Error in dplyr::left_join(): ! Join columns in x must be present in the data. ✖ Problem with variable. Backtrace:

  1. gtsummary::tbl_regression(m, add_pairwise_contrasts = T)
    1. dplyr:::left_join.data.frame(...)

Thanks upfront! Love gtsummary!!!

ddsjoberg commented 1 year ago

Things that work

broom::tidy() model.matrix() model.frame() terms() I didn't inspect the internals of the object though

Things that need to be addressed

larmarange commented 1 year ago

I explored quickly beta regression.

By the way, a nice introduction: https://www.andrewheiss.com/blog/2021/11/08/beta-regression-guide/

Beta regression have something similar with zero-inflated Poisson models, there are multi-components models, as you model both the mean and phi, each could have their own coefficients. Here, (phi) is properly interpreted as an intercept, but this is the intercept of another component.

I will therefore explore it and include betareg support in #233. Next week I'll be on leave but will explore it later after the 12 of August.

A related issue for gtsummary is https://github.com/ddsjoberg/gtsummary/issues/1540

Adding pairwise contrasts for such model is another question. Let's start with basic support and then see if pairwise contrast could be added or not.