Closed larmarange closed 1 year ago
Just added basic support of pairwise contrasts for zeroinfl() models.
Still unsure if this is the correct approach. Right now, we use mode = "count"
and mode = "zero"
for each component. See https://cran.r-project.org/web/packages/emmeans/vignettes/models.html#C
Would the same approach be relevant for beta regression with mode = "response"
and mode = "precision"
.
I'm not sufficiently familiar with these types of models.
A more conservative approach would be to not support pairwise contrast for such models (and throw an error), and letting users to call themselves emmeans
. Support could be added later, once we have feedbacks about what should be expected.
@ddsjoberg What do you think?
library(pscl)
#> Classes and Methods for R developed in the
#> Political Science Computational Laboratory
#> Department of Political Science
#> Stanford University
#> Simon Jackman
#> hurdle and zeroinfl functions by Achim Zeileis
library(broom.helpers)
mod <- zeroinfl(art ~ fem + mar + phd | fem, data = bioChemists)
mod |>
tidy_plus_plus(add_pairwise_contrasts = TRUE, keep_model_terms = TRUE) |>
knitr::kable()
#> ℹ <zeroinfl> model detected.
#> ✔ `tidy_zeroinfl()` used instead.
#> ℹ Add `tidy_fun = broom.helpers::tidy_zeroinfl` to quiet these messages.
component | term | original_term | variable | var_label | var_class | var_type | var_nlevels | contrasts | contrasts_type | reference_row | label | n_obs | estimate | std.error | conf.level | conf.low | conf.high | statistic | df.error | p.value |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
conditional | femMen | NA | fem | fem | factor | dichotomous | 2 | contr.treatment | treatment | TRUE | Men | 494 | 0.0000000 | NA | NA | NA | NA | NA | NA | NA |
conditional | femWomen | count_femWomen | fem | fem | factor | dichotomous | 2 | contr.treatment | treatment | FALSE | Women | 421 | -0.2321456 | 0.0638427 | 0.95 | -0.3572750 | -0.1070162 | -3.6362116 | Inf | 0.0002767 |
zero_inflated | femMen | NA | fem | fem | factor | dichotomous | 2 | contr.treatment | treatment | TRUE | Men | 494 | 0.0000000 | NA | NA | NA | NA | NA | NA | NA |
zero_inflated | femWomen | zero_femWomen | fem | fem | factor | dichotomous | 2 | contr.treatment | treatment | FALSE | Women | 421 | 0.0219932 | 0.2429610 | 0.95 | -0.4542016 | 0.4981881 | 0.0905216 | Inf | 0.9278727 |
NA | Women - Men | NA | fem | fem | factor | dichotomous | 2 | pairwise | pairwise | NA | Women - Men | NA | -0.3910931 | 0.1044908 | NA | -0.5958913 | -0.1862949 | -3.7428481 | NA | 0.0001819 |
conditional | marSingle | NA | mar | mar | factor | dichotomous | 2 | contr.treatment | treatment | TRUE | Single | 309 | 0.0000000 | NA | NA | NA | NA | NA | NA | NA |
conditional | marMarried | count_marMarried | mar | mar | factor | dichotomous | 2 | contr.treatment | treatment | FALSE | Married | 606 | 0.0349971 | 0.0619596 | 0.95 | -0.0864415 | 0.1564358 | 0.5648372 | Inf | 0.5721845 |
NA | Married - Single | NA | mar | mar | factor | dichotomous | 2 | pairwise | pairwise | NA | Married - Single | NA | 0.0581360 | 0.1023191 | NA | -0.1424058 | 0.2586778 | 0.5681832 | NA | 0.5699106 |
conditional | phd | count_phd | phd | phd | numeric | continuous | 2 | NA | NA | NA | phd | 915 | 0.0647841 | 0.0285166 | 0.95 | 0.0088925 | 0.1206756 | 2.2718005 | Inf | 0.0230986 |
Created on 2023-08-06 with reprex v2.0.2
Ooof, I tend to agree with your second comment. It's not a model I've ever used (outside of a brief introduction in school), I would just print a note that it's not supported.
Merging #233 (e3cab2f) into main (7c1b1a0) will decrease coverage by
0.52%
. The diff coverage is87.82%
.
Hi guys,
good new. I managed to find the way to make "add_pairwise_contrasts = T" work with beta-regression. I though you would wanna know that. With the "betareg" package, it still don't work, but it gives a message to use "emmeans", which is fine, but very cumbersome for multivariable models. Ben Bolker also said that's it's perfectly fine to use glmmTMB without random effect! Most of the time the results of betareg and glmmTMB with beta_family are identical. Sometimes a bit different. But the possibility to use {gtsummary} and {broom.helpers} with it makes glmmTMB more valuable! The only thing it does not do is to rename exp(Beta) into OR. But that's no problem at all.
So, I just wanted to let you know, because may be you can build new features into the gtsummary (& broom.helpers) for beta regression (and may be even more, like zeroinfl etc) via glmmTMB package much easier then before. Below is an example without data.
Kind regards and thanks again for your work with broom.helpers and gtsummary. They are amazing!
library(glmmTMB) mod <- glmmTMB(percent ~ breed_kat, data=bla, family = beta_family()) car::Anova(mod) plot_model(mod, type = "pred") tbl_regression(mod, add_pairwise_contrasts = T, exponentiate = T) emmeans(mod, ~ breed_kat, type = "response") %>% pairs(reverse = TRUE)
fix #232 fix #234
betareg()