2

To test whether there is an association between disease groups (categorical_variable) and a disease (outcome; count) I am running 3 negative binomial regression models.

To display the ORs and CIs i am using the tbl_regression function from the package gtsummary. However, this function displays CIs delineated with comma's, where I want them between brackets, and displays p-values, which I want to supress alltogether.

My code:

library(gtsummary)

model <- glm(data=data, formula=outcome ~ categorical_variable)

tbl_regression(model,
    exponentiate = TRUE, 
    include="categorical_variable") 

Any help on formatting the CI's and supressing the p-value column?

I tried adding %>% as_gt() %>% cols_hide("p-value") as well as %>% as_gt() %>% cols_hide(columns=vars("p-value")) but to no avail. It says it does not recognize p-value as a column (also does not work without brackets).

tcvdb1992
  • 413
  • 3
  • 12

2 Answers2

2

If res is the object from the above question that is a gtsummary object, one can modify the table body shown in the viewer pane as follows. Here, I am using dplyr's select function (modify_table_body expects a function) to exclude the p value column.

gtsummary::modify_table_body(res, dplyr::select, -p.value)

I want to use only base:

p_val_col<-which(names(res$table_body)=="p.value")

gtsummary::modify_table_body(res, `[`, -p_val_col)

To also modify the display of ci (you can probably write a much simpler regex than this), run as follows (simulataneously). One could probably write a function that does this at once instead of calling modify_table_body twice:

gtsummary::modify_table_body(res, `[`, -23) %>% 
  gtsummary::modify_table_body(., dplyr::mutate, 
                               ci=gsub("(\\d\\.\\d{,4})(, )(\\d\\.\\d{,4})"
                                                         ,"\\[\\1 \\3\\]",ci))
NelsonGon
  • 13,015
  • 7
  • 27
  • 57
  • 2
    There is also `modify_column_hide()` which won't change the object. – Elin Apr 07 '21 at 11:36
  • Great! Thanks. It already produced the desired result after `gtsummary::modify_table_body(res, dplyr::select, -p.value)`. Would you also know a way of altering the CIs so they are presented between brackets in stead of with a comma between them? Many thanks! – tcvdb1992 Apr 07 '21 at 11:39
  • 1
    @tcvdb1992 Please check the edit. This RegEx assumes that we shall always have digits of the form `0.00` that is 0+dot+at most four digits. – NelsonGon Apr 07 '21 at 11:55
  • 1
    Thanks! I also fixed the first p-value problem by adding ` modify_column_hide(column=p.value)` – tcvdb1992 Apr 07 '21 at 11:59
  • 1
    The CIs are now displayed without a '-' between them.. Would your code also allow for that to be the case? – tcvdb1992 Apr 09 '21 at 08:39
  • 1
    Sorry, for the slow response. If you still need this, you can change `\\[\\1 \\3\\]` to `"\\[\\1-\\3\\]"` which will make them of the form `[0.0001-0.0001]`(random numbers just). @tcvdb1992 – NelsonGon Apr 09 '21 at 13:51
0

As was mentioned by Elin for the single table case:

tbl_regression(model,
  exponentiate = TRUE, 
  include="categorical_variable") %>%
  modify_column_hide(columns = p.value)

For the case with two (or more) regression models:

tbl_merge(
    tbls = list(tbl_regression(model1),
                tbl_regression(model2))
    )  %>% 
    modify_column_hide(columns = c(p.value_1, p.value_2)