1.6 Descriptive tables with {gtsummary}
Slides
Open the slides in a new tab here.
Exercises
- Download the R script here and put it into your in-class project folder.
- Install
{gtsummary}
and run the examples. - Make a
tbl_summary()
. Include categorical region, race/ethnicity, income, and the sleep variables (use a helper function to select those) and make sure they are nicely labeled. - Stratify the table by sex. Add a p-value comparing the sexes and an overall column combining both sexes.
- For the income variable, show the 10th and 90th percentiles of income with 3 digits, and for the sleep variables, show the min and the max with 1 digit.
- Add a footnote to the race/ethnicity variable with a link to the page describing how NLSY classified participants: https://www.nlsinfo.org/content/cohorts/nlsy79/topical-guide/household/race-ethnicity-immigration-data
- Play around with the extra functions from the examples and/or from the documentation