Search code examples
rgtsummary

Any way to display standard error of beta estimate in tbl_regression?


I haven't seen any way to print the SE of a model estimate using gtsummary::tbl_regression.

Any way to add SE to the model output columns when printing a table using tbl_regression?

library(gtsummary)
test <- with(trial, lm(marker~trt+age))
tbl_regression(test)

Solution

  • Hiding and unhiding columns has been made much easier in the current development version of gtsummary (while it is possible in v1.3.5, it requires more understanding of the internals of gtsummary). I recommend installing the development version and executing the code below.

    You can hide or unhide any of the columns in x$table_body (where x is the gtsummary object). In nearly every regression model, there is a hidden column called "std.error" and the code below prints the column.

    http://www.danieldsjoberg.com/gtsummary/dev/reference/modify_column_hide.html

    remotes::install_github("ddsjoberg/gtsummary")
    library(gtsummary)
    packageVersion("gtsummary")
    #> [1] "1.3.5.9014"
    
    # hide 95% CI, and replace with standard error
    modify_column_hide_ex1 <-
      lm(age ~ marker + grade, trial) %>%
      tbl_regression() %>%
      modify_column_hide(column = ci) %>%
      modify_column_unhide(column = std.error)
    

    enter image description here