1.7 Regression tables with {gtsummary}
Slides
Open the slides in a new tab here.
Exercises
- Download the R script
regression-examples.Rand add it to your in-class project folder. (Commit and push) - Run the examples. We’ll come back together and talk about these.
- Each of the univariate regression examples held the outcome (
y =) constant, while varying the predictor variables withinclude =. You can also look at one predictor across several outcomes. Create a univariate regression table looking at the association between sex (sex_cat) as thex =variable and each ofnsibs,sleep_wkdy, andsleep_wknd, andincome.
- Hint: You can use almost the same code as the univariate regression table examples from the code. Did we need to fit the regressions ahead of time for that?
- Fit a Poisson regression (
family = poisson()) for the number of siblings, using at least 3 predictors of your choice. Create a nice table displaying your Poisson regression and its exponentiated coefficients.
- Hint: You can use almost the same code (two parts!) we used for the logistic regression table in the code.
- Instead of odds ratios for wearing glasses, as in the example in the slides., we want risk ratios. We can do this by specifying in the regression
family = binomial(link = "log"). Regressglassesoneyesight_catandsex_catand create a table showing the risk ratios and confidence intervals from this regression. - Make a table comparing the logistic and the log-binomial results.
Commit and push!
Bonus: Since family = binomial(link = "log") often doesn’t converge, we often use Poisson regression with robust standard errors to estimate risk ratios. Fit a Poisson regression instead of the log-binomial regression for question 6. Then create a table using tidy_fun = partial(tidy_robust, vcov = "HC1"). It will prompt you to install new package(s) (yes!). See this page for more on custom tidiers.