--- title: "Regression Tables" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Regression Tables} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- # Regression Tables Go from fitted models to publication-ready tables without hand-formatting effect estimates. `gtregression` supports logistic, log-binomial, Poisson, robust Poisson, negative binomial, and linear regression. ```{r reg-setup, message=FALSE, warning=FALSE} library(gtregression) library(dplyr) data("data_birthwt", package = "gtregression") birthwt_data <- data_birthwt |> mutate( race = factor(race, levels = c(1, 2, 3), labels = c("White", "Black", "Other")), smoke = factor(smoke, levels = c(0, 1), labels = c("No", "Yes")), ht = factor(ht, levels = c(0, 1), labels = c("No", "Yes")), ui = factor(ui, levels = c(0, 1), labels = c("No", "Yes")), low = factor(low, levels = c(0, 1), labels = c("Normal BW", "Low BW")), ptl_cat = factor(ifelse(ptl > 0, "Yes", "No"), levels = c("No", "Yes")), ftv_cat = factor(case_when( ftv == 0 ~ "None", ftv == 1 ~ "One", ftv >= 2 ~ "Two or more" ), levels = c("None", "One", "Two or more")) ) birthwt_exposures <- c( "age", "lwt", "race", "smoke", "ht", "ui", "ptl_cat", "ftv_cat" ) ``` ## Univariable Models `uni_reg()` fits one model per exposure and returns a table ready for reports. ```{r uni-logit, message=FALSE, warning=FALSE} birthwt_uni <- uni_reg( data = birthwt_data, outcome = "low", exposures = birthwt_exposures, approach = "logit", theme = clinical ) birthwt_uni$table ``` ## Adjusted Models `multi_reg()` can fit all exposures in one model, or fit one adjusted model per exposure using the same adjustment set. ```{r multi-adjusted, message=FALSE, warning=FALSE} birthwt_multi <- multi_reg( data = birthwt_data, outcome = "low", exposures = c("smoke", "ht", "ui", "ptl_cat", "ftv_cat"), adjust_for = c("age", "lwt", "race"), approach = "logit", theme = striped ) birthwt_multi$table ``` The adjustment variables are recorded in the table footnote so the result is ready for manuscript-style reporting. ## Other Effect Measures Switch the `approach` to change the estimand. ```{r reg-risk-ratio, message=FALSE, warning=FALSE} uni_reg( data = birthwt_data, outcome = "low", exposures = c("smoke", "ht", "ui", "ptl_cat"), approach = "logbinomial" )$table ``` ## Continuous Outcomes Linear regression outputs beta coefficients and keeps diagnostics under `$reg_check`. ```{r reg-linear, message=FALSE, warning=FALSE} birthwt_linear <- multi_reg( data = birthwt_data, outcome = "bwt", exposures = c("age", "lwt", "race", "smoke", "ht", "ui"), approach = "linear" ) birthwt_linear$table ``` ## What To Inspect - `$table`: publication-ready table. - `$table_body`: numeric estimates behind the display. - `$models`: fitted model objects. - `$model_summaries`: model-level summaries. - `$reg_check`: diagnostics for linear models.