This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(gtsummary) | |
library(broom.helpers) | |
library(tidyverse) | |
packageVersion("gtsummary") | |
#> [1] '1.6.0' | |
# build model | |
mod <- biglm::bigglm(response ~ age + trt, data = trial, family = binomial()) | |
# build a fancy tidy data frame one step at a time |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(gtsummary) | |
library(tidyverse) | |
trial %>% | |
tbl_strata( | |
strata = trt, | |
~ .x %>% | |
nest(data = -grade) %>% | |
arrange(grade) %>% | |
rowwise() %>% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gt_rainbow_stripes <- function(x, rep_n = 5) { | |
x <- | |
gt::cols_width(x, label ~ gt::px(130)) %>% | |
gt::tab_header( | |
title = x[["_heading"]]$title, | |
subtitle = "But Make it G - A - Y" | |
) %>% | |
gt::tab_options(heading.subtitle.font.size = 20, | |
heading.subtitle.font.weight = "bolder") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set.seed(20210511) | |
library(gtsummary) | |
library(magrittr) | |
multinom_pivot_wider <- function(x) { | |
# check inputs match expectatations | |
if (!inherits(x, "tbl_regression") || !inherits(x$model_obj, "multinom")) { | |
stop("`x=` must be class 'tbl_regression' summary of a `nnet::multinom()` model.") | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ANALYSIS Rmd FILE | |
```{r} | |
# create a gtsummary table | |
tbl <- trial %>% tbl_summary() | |
# save it to file | |
saveRDS(tbl, file = "my_tbl_summary1.Rds") | |
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
split_gtsummary_tbl <- function(x, .split_after) { | |
# get row index where splits occur | |
df_index <- | |
.split_after %>% | |
purrr::map_int(~x$table_body$variable %in% .x %>% | |
which() %>% | |
max()) %>% | |
{union(., nrow(x$table_body))} %>% | |
sort() %>% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use_significance_stars <- function(x) { | |
if (!"estimate" %in% names(x$table_body)) return(x) | |
# extracting old estimate fun | |
old_est_fun <- switch( | |
!is.null(x$table_header), | |
x$table_header %>% | |
dplyr::filter(column == "estimate") %>% | |
purrr::pluck("fmt_fun", 1) | |
) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(gtsummary) | |
trial %>% | |
select(marker, trt) %>% | |
tbl_summary( | |
by = trt, | |
missing = "no", | |
statistic = everything() ~ "{mean} ({sd})", | |
# use a function to style output, rather than specify number of decimal places | |
digits = everything() ~ style_sigfig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Original stack overflow post | |
# https://stackoverflow.com/questions/65673290/merging-tbl-svysummary-and-stacked-tbl-regression-tables-with-different-variable | |
library(gtsummary) | |
packageVersion("gtsummary") | |
#> '1.3.6' | |
# 1. build reg models for varying outcomes, | |
# 2. show covariate for age in table for all outcomes, | |
# 3. adjust all models for marker level |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' @import dplyr %>% | |
#' @import purrr %||% | |
tbl_cmh <- function(data, case, exposure, strata, | |
label = NULL, | |
estimate_fun = gtsummary::style_ratio, | |
overall_or = TRUE, | |
overall_label = "Crude") { | |
# converting selectors to character names ------------------------------------ | |
case <- dplyr::select(data, {{ case }}) %>% names() | |
exposure <- dplyr::select(data, {{ exposure }}) %>% names() |
NewerOlder