Closed larmarange closed 1 year ago
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.
I need to check. I guess that this is not covered by emmeans. But not sure
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
@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
Merging #192 (c27d9b3) into main (46e8c6d) will decrease coverage by
0.23%
. The diff coverage is93.33%
.