knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

tidycmprsk

R-CMD-check Codecov test coverage CRAN status

The tidycmprsk package provides an intuitive interface for working with the competing risk endpoints. The package wraps the cmprsk package, and exports functions for univariate cumulative incidence estimates with cuminc() and competing risk regression with crr().

The package also includes broom-style tidiers: tidy(), augment(), and glance().

Installation

You can install {tidycmprsk} with the following code.

install.packages("tidycmprsk")

Install the development version of {tidycmprsk} with:

# install.packages("devtools")
devtools::install_github("MSKCC-Epi-Bio/tidycmprsk")

Competing Risk Regression

Fit a Fine and Gray competing risks regression model using the the example data, trial.

library(tidycmprsk)

crr_mod <- crr(Surv(ttdeath, death_cr) ~ age + trt, trial)
crr_mod

The tidycmprsk plays well with other packages, such as gtsummary.

tbl <- 
  crr_mod %>%
  gtsummary::tbl_regression(exponentiate = TRUE) %>%
  gtsummary::add_global_p() %>%
  add_n(location = "level")
# Had to manually save images in temp file, not sure if better way.
gt::gtsave(gtsummary::as_gt(tbl), file = "man/figures/README-gtsummary-crr.png")
# Have to do this workaround since the README needs markdown format for GitHub page but a different format for the website.
if (identical(Sys.getenv("IN_PKGDOWN"), "true")) {
  tbl
} else {
  knitr::include_graphics("man/figures/README-gtsummary-crr.png")
} 
gtsummary::inline_text(tbl, variable = age)

Cumulative Incidence

cuminc(Surv(ttdeath, death_cr) ~ 1, trial)

Plot risks using using the {ggsurvfit} package.

library(ggsurvfit)

cuminc(Surv(ttdeath, death_cr) ~ trt, trial) %>%
  ggcuminc() +
  add_confidence_interval() +
  add_risktable() +
  scale_ggsurvfit(x_scales = list(breaks = seq(0, 24, by = 6)))

Summary table

tbl <- 
  cuminc(Surv(ttdeath, death_cr) ~ trt, trial) %>%
  tbl_cuminc(times = c(12, 24), label_header = "**Month {time}**") %>%
  add_p() %>%
  add_n()
# Had to manually save images in temp file, not sure if better way.
gt::gtsave(gtsummary::as_gt(tbl), file = "man/figures/README-gtsummary-cuminc.png")
# Have to do this workaround since the README needs markdown format for GitHub page but a different format for the website.
if (identical(Sys.getenv("IN_PKGDOWN"), "true")) {
  tbl
} else {
  knitr::include_graphics("man/figures/README-gtsummary-cuminc.png")
} 

Contributing

Please note that the {tidycmprsk} project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms. Thank you to all contributors!
r usethis::use_tidy_thanks("mskcc-epi-bio/tidycmprsk", from = "2018-01-01") %>% {glue::glue("[&#x0040;{.}](https://github.com/{.})")} %>% glue::glue_collapse(sep = ", ", last = ", and ")

Limitations

The tidycmprsk package implements most features (and more) available in cmprsk. However, the time interaction features available in cmprsk::crr() is not available in tidycmprsk.



MSKCC-Epi-Bio/tidycmprsk documentation built on Aug. 19, 2024, 4:40 a.m.