Skip to content
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

Add an option contrast_adjust to be passed to pairs() when add_pairwise_contrasts = TRUE #204

Closed
yuryzablotski opened this issue Jan 12, 2023 · 2 comments · Fixed by #212

Comments

@yuryzablotski
Copy link

Hi Joseph,

first, thanks a ton for {broom.helpers}! I am a big fan! Alone the "add_pairwise_contrasts" is incredibly useful!!! I started to use it on a daily basis and discovered a small inconsistency. Namely, adjust = "none", is not possible right now. And the add_pairwise_contrasts just uses Tukey (default from Emmeans) by default. Which is cool and fine, since we need to adjust for multiple testing, but if in the future you could implement "none" method of adjustment, that'll be cool. Below is the prove of this small issue. Kind regards! Yury

m <- glm(am ~ cyl, mtcars %>% mutate(cyl = factor(cyl)), family = binomial)

tbl_regression(
m,
exponentiate = T,
pvalue_fun = ~style_pvalue(.x, digits = 3),
add_pairwise_contrasts = T) %>%
add_n(location = "level") %>%
add_nevent(location = "level") %>%
add_significance_stars(hide_p = F, hide_se = T, hide_ci = F) %>%
add_q(method = "none")

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

emmeans(m, ~ cyl, type = "response") %>% pairs(reverse = T, adjust = "tukey")

emmeans(m, ~ cyl, type = "response") %>% pairs(reverse = T, adjust = "none")

@larmarange
Copy link
Owner

Did you try to use emm_options()?

library(emmeans)
library(gtsummary)

m <- glm(am ~ cyl, mtcars %>% mutate(cyl = factor(cyl)), family = binomial)

emmeans(m, "cyl", type = "response") %>% pairs(reverse = T)
#>  contrast    odds.ratio     SE  df null z.ratio p.value
#>  cyl6 / cyl4     0.2812 0.2870 Inf    1  -1.243  0.4279
#>  cyl8 / cyl4     0.0625 0.0638 Inf    1  -2.717  0.0181
#>  cyl8 / cyl6     0.2222 0.2400 Inf    1  -1.393  0.3448
#> 
#> P value adjustment: tukey method for comparing a family of 3 estimates 
#> Tests are performed on the log odds ratio scale

tbl_regression(m, add_pairwise_contrasts = TRUE) %>% as_kable()
Characteristic log(OR) 95% CI p-value
cyl
cyl6 - cyl4 -1.3 -3.7, 1.1 0.4
cyl8 - cyl4 -2.8 -5.2, -0.38 0.018
cyl8 - cyl6 -1.5 -4.0, 1.0 0.3
emmeans(m, "cyl", type = "response") %>% pairs(reverse = T, adjust = "none")
#>  contrast    odds.ratio     SE  df null z.ratio p.value
#>  cyl6 / cyl4     0.2812 0.2870 Inf    1  -1.243  0.2139
#>  cyl8 / cyl4     0.0625 0.0638 Inf    1  -2.717  0.0066
#>  cyl8 / cyl6     0.2222 0.2400 Inf    1  -1.393  0.1638
#> 
#> Tests are performed on the log odds ratio scale

emm_options(contrast = list(adjust = "none"))
emmeans(m, "cyl", type = "response") %>% pairs(reverse = T)
#>  contrast    odds.ratio     SE  df null z.ratio p.value
#>  cyl6 / cyl4     0.2812 0.2870 Inf    1  -1.243  0.2139
#>  cyl8 / cyl4     0.0625 0.0638 Inf    1  -2.717  0.0066
#>  cyl8 / cyl6     0.2222 0.2400 Inf    1  -1.393  0.1638
#> 
#> Tests are performed on the log odds ratio scale
tbl_regression(m, add_pairwise_contrasts = TRUE) %>% as_kable()
Characteristic log(OR) 95% CI p-value
cyl
cyl6 - cyl4 -1.3 -3.3, 0.73 0.2
cyl8 - cyl4 -2.8 -4.8, -0.77 0.007
cyl8 - cyl6 -1.5 -3.6, 0.61 0.2

Created on 2023-01-12 with reprex v2.0.2

@larmarange larmarange changed the title add_pairwise_contrasts = T uses adjust = "tukey" by default, not adjust = "none". for now it's impossible to use adjust = "none"" Add an option contrast_adjust to be passed to pairs() when add_pairwise_contrasts = TRUE Jan 12, 2023
@yuryzablotski
Copy link
Author

yes, I tried to use it inside of both "tbl_regression()" and "tidy_add_pairwise_contrasts()", but could not manage to get method = "none" working.

But now I tried this and it did work! (example below) Thanks! It is actually better when the default corrects for multiple comparisons, but, as you already changed the name of the issue, it would be nice, when the adjust = "none" would work directly inside of either tbl_regression() or add_pairwise_contrasts() or add_q(). Thanks again!

make adjust = "none" the default

emm_options(contrast = list(adjust = "none"))

tbl_regression(
m,
exponentiate = T,
pvalue_fun = ~style_pvalue(.x, digits = 3),
add_pairwise_contrasts = T) %>%
add_n(location = "level") %>%
add_nevent(location = "level") %>%
add_significance_stars(
hide_p = F, hide_se = T, hide_ci = F) %>%
add_q()

return to "tukey" as a "termporary?" default

emm_options(disable = TRUE)

larmarange added a commit that referenced this issue Feb 7, 2023
in `tidy_plus_plus()`,
  `tidy_add_pairwise_contrasts()` and `model_get_pairwise_contrasts()` allowing
  to change the adjustment method used to compute pairwise contrasts

fix #204
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants