Reputation: 29
I am trying to create a table using gtsummary. To give some insight, here is my current code so far:
# variables associated with Interpreter Use
table1 <- tbl_summary(pre_int, include = c('Age', 'Gender_Identity'),
by = 'Interpreter Used') %>%
add_n() %>%
modify_header(label = "**Variable**") %>%
bold_labels() %>% add_p()
I am getting the following output as an example:
I want to add a few things to the code:
Any help on how to format the code in order to add these changes? Would appreciate any help. I've tried to look at the documentation but I wasn't able to adapt this code accordingly.
To experiment, here's some sample data:
Age | Gender Identity | Interpreter Used |
---|---|---|
7 | White non-Hispanic | Yes |
15 | Other | No |
8 | Black non-Hispanic | No |
10 | White non-Hispanic | No |
8 | White non-Hispanic | Yes |
15 | White non-Hispanic | Yes |
Thank you!
Upvotes: 0
Views: 270
Reputation: 11680
- Fix the percentages such that they display to two significant digits
Use the argument tbl_summary(digits = all_categorical() ~ c(0, 2)
- Get the p-values generated for the subcategories rather than just the main categories (for example generating a p-value for gender identity female, male, etc.)
P-values are added an a per-variable basis. To get a p-value for each level of a categorical variable, you must create dummy variables for each level, then add them to the table.
- Get the mean and SD for age rather than median and IQR.
Use the argument tbl_summary(statistic = age ~ "{mean} ({sd})")
Upvotes: 0