Is there a way to supress p-values in tbl_regression function in R?

Viewed 279

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).

2 Answers

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))

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)
Related