Reputation: 73
in the example online, there is:
mod1 <- glm(response ~ trt + age + grade, trial, family = binomial)
t1 <- tbl_regression(mod1, exponentiate = TRUE)
It produces a nice regression table that works, but how can I write the code for just showing Grade 1 instead of all of the Grades 1 through 3. And, if there was a row that was inherently binary (0 or 1), how can I choose just the true one?
I tried the label = list(.....)
and value = list(...)
, but this is not an option I saw on the package information for gtsummary
, and did not work when I tried. There must be an easy way to do this or I am not searching hard enough in the write-up. Thanks!
Upvotes: 1
Views: 2088
Reputation: 11680
Question 1: Grade is a variable with three levels and you want to show this result on a single line. You can use the Wald or Likelihood ratio test to test for the significance of Grade altogether and print the single p-value using the combine_terms()
function. Note that you will no longer see the 2 beta coefficients associated with Grade II and Grade III.
Question 2: The tbl_regression()
model will print the results as they were entered into glm()
. Numeric variables are interpreted as continuous and print on a single row. All others print on multiple rows. If you have a variable coded as 0/1, it will print on a single row. To show both levels, you can add factor()
around it. If you are in the opposite situation where you have a binary variable printing on multiple rows and want it shown on a single row, you can use the tbl_regression(show_single_row=)
argument.
Example 1:
Show Grade on a single row, with default printing for "trt"
(character) and "death"
(numeric 0/1). "trt"
prints on two rows, and "death"
prints on a single row.
library(gtsummary)
glm(response ~ trt + grade + death, trial, family = binomial) %>%
tbl_regression(exponentiate = TRUE) %>%
combine_terms(formula_update = . ~ . - grade, test = "LRT")
Example 2:
Now we will print "trt"
on a single row, and "death"
prints on two rows.
glm(response ~ trt + factor(death), trial, family = binomial) %>%
tbl_regression(
exponentiate = TRUE,
show_single_row = trt,
label = list(
trt ~ "Drug B vs A (reference group)",
`factor(death)` ~ "Death"
)
)
Upvotes: 2