New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Displaying margin effects, average margin effects or conditional effects #195
Conversation
library(broom.helpers)
library(gtsummary)
#>
#> Attachement du package : 'gtsummary'
#> Les objets suivants sont masqués depuis 'package:broom.helpers':
#>
#> all_continuous, all_contrasts
mod <- glm(response ~ stage + grade + age, family = binomial, data = trial)
mod %>%
tbl_regression(
tidy_fun = tidy_margins,
estimate_fun = scales::label_percent(style_positive = "plus")
) %>%
as_kable()
mod %>%
tbl_regression(
tidy_fun = tidy_all_effects,
estimate_fun = scales::label_percent()
) %>%
as_kable()
mod %>%
tbl_regression(
tidy_fun = tidy_ggpredict,
estimate_fun = scales::label_percent()
) %>%
as_kable()
#> Data were 'prettified'. Consider using `terms="age [all]"` to get smooth
#> plots.
Created on 2022-12-10 with reprex v2.0.2 |
@ddsjoberg I had to prepare a course on marginal effects and I was realising that they were no nicely formatted output for such a thing. This is exploratory work, but it seems quite easy to implement using customer tieders in As you can see, the results are nicely formatted by It probably needs to mature a little. Do not hesitate if you have any feedback. |
@larmarange the update looks awesome! |
@ddsjoberg Any comment about the name of the estimate column? |
I think |
Currently, I'm using "Average Marginal Effect", "Marginal Effect" and "Conditional Effect". I would prefer to be explicit (as we do with OR for logistic regression). Does that seem OK? Or would you prefer "AME"? (but less known) |
@ddsjoberg do you want to have a look at this PR before merge? |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #195 +/- ##
==========================================
- Coverage 97.80% 97.54% -0.26%
==========================================
Files 40 40
Lines 1870 1958 +88
==========================================
+ Hits 1829 1910 +81
- Misses 41 48 +7
|
First draft of support of margin effects (with
effects::allEffects()
), average margin effects (frommargins::margins()
) and conditional effects (withggeffects::ggpredict()
).Need to mature and to be tested. Requires proper documentation, unit tests and examples.