Skip to content

Support for pairwise contrasts from emmeans #192

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

Merged
merged 15 commits into from
Dec 12, 2022
Merged

Support for pairwise contrasts from emmeans #192

merged 15 commits into from
Dec 12, 2022

Conversation

larmarange
Copy link
Owner

@larmarange larmarange commented Nov 11, 2022

  • to be finalised
  • update doc
  • add test
  • update vignette
  • update NEWS and README

@larmarange larmarange requested a review from ddsjoberg November 21, 2022 20:08
@ddsjoberg
Copy link
Collaborator

hey hey @larmarange !

this all looks great!

I was doing some testing with other types of contrasts. do you think we should document in the help file how various contrasts are handled? for example, if you make a ploy contrast from a factor variable, it is ignored by this new function.

@larmarange
Copy link
Owner Author

I need to check. I guess that this is not covered by emmeans. But not sure

@larmarange
Copy link
Owner Author

It seems to work indeed. What was your exact test?

library(gtsummary)
library(broom.helpers)
#> 
#> Attachement du package : 'broom.helpers'
#> Les objets suivants sont masqués depuis 'package:gtsummary':
#> 
#>     all_continuous, all_contrasts

mod <- glm(
  response ~ stage + grade + trt,
  gtsummary::trial,
  family = binomial,
  contrasts = list(
    stage = contr.sum,
    grade = contr.helmert,
    trt = contr.poly
  )
)


mod |> 
  tbl_regression(exponentiate = TRUE, add_pairwise_contrasts = TRUE) |> 
  as_kable()
Characteristic OR 95% CI p-value
T Stage
T2 / T1 0.61 0.20, 1.86 0.7
T3 / T1 1.10 0.35, 3.45 >0.9
T3 / T2 1.82 0.56, 5.94 0.6
T4 / T1 0.81 0.27, 2.42 >0.9
T4 / T2 1.33 0.42, 4.18 >0.9
T4 / T3 0.73 0.23, 2.34 0.9
Grade
II / I 0.96 0.39, 2.37 >0.9
III / I 1.13 0.47, 2.76 >0.9
III / II 1.19 0.48, 2.95 0.9
Chemotherapy Treatment
Drug B / Drug A 1.24 0.67, 2.29 0.5

Created on 2022-11-23 with reprex v2.0.2

@ddsjoberg
Copy link
Collaborator

@larmarange that is great! The contrast I looked at was the one from ordered factor variables:

library(broom.helpers)

mod <- glm(response ~ factor(stage, ordered = TRUE) + trt, gtsummary::trial, family = binomial)

mod %>%
  tidy_and_attach(exponentiate = TRUE) %>%
  tidy_add_pairwise_contrasts() %>%
  dplyr::select(term, variable, var_class, var_type, contrasts, contrasts_type, estimate) %>%
  knitr::kable()
term variable var_class var_type contrasts contrasts_type estimate
(Intercept) (Intercept) NA intercept NA NA 0.4153831
factor(stage, ordered = TRUE).L factor(stage, ordered = TRUE) ordered continuous contr.poly poly 1.0009112
factor(stage, ordered = TRUE).Q factor(stage, ordered = TRUE) ordered continuous contr.poly poly 1.0862980
factor(stage, ordered = TRUE).C factor(stage, ordered = TRUE) ordered continuous contr.poly poly 0.6407352
Drug B / Drug A trt character dichotomous pairwise pairwise 1.2431465

Created on 2022-11-23 with reprex v2.0.2

Copy link
Collaborator

@ddsjoberg ddsjoberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🦁

@codecov
Copy link

codecov bot commented Dec 10, 2022

Codecov Report

Merging #192 (c27d9b3) into main (46e8c6d) will decrease coverage by 0.23%.
The diff coverage is 93.33%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #192      +/-   ##
==========================================
- Coverage   98.03%   97.80%   -0.24%     
==========================================
  Files          38       40       +2     
  Lines        1785     1870      +85     
==========================================
+ Hits         1750     1829      +79     
- Misses         35       41       +6     
Impacted Files Coverage Δ
R/model_get_pairwise_contrasts.R 88.88% <88.88%> (ø)
R/tidy_add_pairwise_contrasts.R 93.75% <93.75%> (ø)
R/broom.helpers-package.R 100.00% <100.00%> (ø)
R/tidy_and_attach.R 100.00% <100.00%> (ø)
R/tidy_plus_plus.R 100.00% <100.00%> (ø)

@larmarange larmarange merged commit cd81d97 into main Dec 12, 2022
@larmarange larmarange deleted the pairwise branch December 12, 2022 14:05
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 this pull request may close these issues.

2 participants