1.7 Regression tables with {gtsummary}

Slides

Open the slides in a new tab here.

Exercises

  1. Download the R script regression-examples.R and add it to your in-class project folder. (Commit and push)
  2. Run the examples. We’ll come back together and talk about these.
  3. Each of the univariate regression examples held the outcome (y =) constant, while varying the predictor variables with include =. You can also look at one predictor across several outcomes. Create a univariate regression table looking at the association between sex (sex_cat) as the x = variable and each of nsibs, sleep_wkdy, and sleep_wknd, and income.
  • 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?
  1. 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.
  1. 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"). Regress glasses on eyesight_cat and sex_cat and create a table showing the risk ratios and confidence intervals from this regression.
  2. 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.

Resources