Search code examples
rgtsummary

Remove p-value column of gtsummary linear regression table


I am using gtsummary to summarise my linear regression results. I am trying to omit out the p-value for each sex (column.

Any support on this would be greatly appreciated. I have included dummy data to reproduce what I am trying to do, as well as an image of my linear reg table as it stand.

# install dev versions
remotes::install_github("ddsjoberg/gtsummary@mice_nnet")
remotes::install_github("larmarange/broom.helpers")

# load packages
library(gtsummary)
library(nnet)
theme_gtsummary_compact()

# dummy data 
crime <-data.frame(city = sample(c("SF", "AR", "NYC","MN"),13000,replace = TRUE),
                   sex = sample(c("Male", "Female"),13000,replace = TRUE),
                   year = sample(as.numeric(sample(10:20, 13000, replace = TRUE)))
                   )

# serperate data sets by sex
crime_f <- crime %>%
  filter(sex == "Female")
crime_m <- crime %>%
  filter(sex == "Male")

# build model for females
mod_f <- lm(year ~ city, data = crime_f) %>%
  tbl_regression(exponentiate = TRUE) %>%
  modify_header(estimate ~ "**OR**")

# build model for males
mod_m <- lm(year ~ city, data = crime_m) %>%
  tbl_regression(exponentiate = TRUE) %>%
  modify_header(estimate ~ "**OR**")


# lm model tabulated with gtsummary  
tbl <- tbl_merge(
  tbls = list(mod_f, mod_m),
  tab_spanner = c("**Female**", "**Male**")
  )

tbl # check table

enter image description here


Solution

  • With the modify_table_header() function you can chose to hide columns in your output, including p-values:

    tbl %>%
      modify_table_header(
        column = c(p.value_1, p.value_2),
        hide = TRUE
      )
    

    enter image description here

    Good luck!