-
Notifications
You must be signed in to change notification settings - Fork 130
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
Customize reference level for tbl_regression() #628
Comments
Hey hey! Can you give an example model and a resulting table? I can easily add an option to print Reference instead of an emdash. |
An example from your Table Gallery vignette (this paged helped me a lot): gt_r1 <- glm(response ~ age + trt, trial, family = binomial) %>% gives: https://user-images.githubusercontent.com/35614530/90699607-94294500-e238-11ea-8c58-9215838ec64e.png I had in mind "1" in the OR column and "Reference" in the 95% CI column, in place of the emdashes. |
Ok I see. I don't have any plans for implementing something like this at the moment. I wrote you a small wrapper that will produce the table you're looking for. as_gt_tjmeyers <- function(x) {
# adding either 0 or 1 value as reference
ref_value <- ifelse(x$inputs$exponentiate, 1, 0)
x$table_body$estimate <-
ifelse(x$table_body$row_ref== TRUE & is.na(x$table_body$estimate),
ref_value,
x$table_body$estimate)
# adding "Reference" to CI ref row
gtsummary::as_gt(x) %>%
gt::fmt_missing(columns = vars(ci), rows = row_ref== TRUE & is.na(ci), "Reference")
}
glm(response ~ stage, trial, family = binomial()) %>%
tbl_regression(exponentiate = TRUE) %>%
as_gt_tjmeyers() This is a little trickier to implement broadly, because it straddles making updates to the underlying gtsummary object and the printing method-- But we do have a new initiative to support formats for various journals (http://www.danieldsjoberg.com/gtsummary/reference/theme_gtsummary.html). If there is a journal with published reporting guidelines that explicitly asks for reference rows to be reported like this, I can begin to ponder how something like this could be integrated into the package. Happy Programming! 🕺 |
Thank you. This is clever and I'm sure others will find this helpful. I should've mentioned that my preferred printing method is |
Hmmm, after you run tt <- tbl_summary(trial) %>% as_flex_table()
tt$body$dataset <-
tt$body$dataset %>%
mutate( *add code here to change the reference label* )
# print the table
tt |
I'm able to modify the variables in tt$body$dataset but the table did not contain the updated data.
|
The code you are applying to |
Hi @tjmeyers , FYI, I've made updates internally to let you accomplish your goal. Example below: list("tbl_regression-lgl:add_ref_est" = TRUE,
"tbl_regression-str:ref_row_text" = "Reference") %>%
set_gtsummary_theme()
mtcars %>%
mutate(cyl = factor(cyl)) %>%
select("am", "hp", "cyl") %>%
tbl_uvregression(
method = glm,
y = am,
formula = "{y} ~ {x}",
method.args = list(family = binomial),
# label = "cyl" ~ "No. Cylinders",
hide_n = TRUE,
exponentiate = TRUE
) The update is in this pull request #606 After the update has gone through code review, it'll be merged into master branch, and eventually released on CRAN |
Great thank you!
Travis
…On Wed, Sep 2, 2020 at 4:34 PM Daniel Sjoberg ***@***.***> wrote:
Hi @tjmeyers <https://github.com/tjmeyers> ,
FYI, I've made updates internally to let you accomplish your goal. Example
below:
list("tbl_regression-lgl:add_ref_est" = TRUE,
"tbl_regression-str:ref_row_text" = "Reference") %>%
set_gtsummary_theme()
mtcars %>%
mutate(cyl = factor(cyl)) %>%
select("am", "hp", "cyl") %>%
tbl_uvregression(
method = glm,
y = am,
formula = "{y} ~ {x}",
method.args = list(family = binomial),
# label = "cyl" ~ "No. Cylinders",
hide_n = TRUE,
exponentiate = TRUE
)
[image: image]
<https://user-images.githubusercontent.com/26774684/92047435-1d6d6b00-ed53-11ea-98ed-1c445a6a7f8f.png>
The update is in this pull request #606
<#606>
After the update has gone through code review, it'll be merged into master
branch, and eventually released on CRAN
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#628 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AIPW6QQSDG6EO27Z7OJ5AT3SD3JARANCNFSM4QFMLDGQ>
.
|
If you'd like, you can open another issue, and we can eventually add a theme for the journals you submit to that prefer this format. You'd then be able to apply this option, and other options the journal guidelines state, in a single line. |
Hi Daniel! Thank you for all your work on gtsummary; it's an amazing tool! One feature I would find useful is to customize the reference level indicator for regression models. That is, instead of printing an emdash for the reference level in a categorical variable, I would like to print "1" in the estimate column and "Reference" in the confidence interval column. Do you have any plans to develop this feature? Thank you.
The text was updated successfully, but these errors were encountered: