-
Notifications
You must be signed in to change notification settings - Fork 6
/
README.Rmd
135 lines (102 loc) · 4.26 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# tidycmprsk <a href="https://mskcc-epi-bio.github.io/tidycmprsk/"><img src="man/figures/logo.png" align="right" height="138" /></a>
<!-- badges: start -->
[![R-CMD-check](https://github.com/MSKCC-Epi-Bio/tidycmprsk/actions/workflows/R-CMD-check.yaml/badge.svg?branch=main)](https://github.com/MSKCC-Epi-Bio/tidycmprsk/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/MSKCC-Epi-Bio/tidycmprsk/branch/main/graph/badge.svg)](https://app.codecov.io/gh/MSKCC-Epi-Bio/tidycmprsk?branch=main)
[![CRAN status](https://www.r-pkg.org/badges/version/tidycmprsk)](https://cran.r-project.org/package=tidycmprsk)
[![](https://cranlogs.r-pkg.org/badges/tidycmprsk)](https://cran.r-project.org/package=tidycmprsk)
<!-- badges: end -->
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.
``` r
install.packages("tidycmprsk")
```
Install the development version of {tidycmprsk} with:
``` r
# 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`.
```{r example}
library(tidycmprsk)
crr_mod <- crr(Surv(ttdeath, death_cr) ~ age + trt, trial)
crr_mod
```
The `tidycmprsk` plays well with other packages, such as `gtsummary`.
```{r gtsummary, message = FALSE}
tbl <-
crr_mod %>%
gtsummary::tbl_regression(exponentiate = TRUE) %>%
gtsummary::add_global_p() %>%
add_n(location = "level")
```
```{r gtsummary_print, include = FALSE}
# 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")
```
```{r out.width = "50%", echo = FALSE}
# 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")
}
```
```{r}
gtsummary::inline_text(tbl, variable = age)
```
## Cumulative Incidence
```{r}
cuminc(Surv(ttdeath, death_cr) ~ 1, trial)
```
Plot risks using using the {ggsurvfit} package.
```{r}
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
```{r tbl_cuminc}
tbl <-
cuminc(Surv(ttdeath, death_cr) ~ trt, trial) %>%
tbl_cuminc(times = c(12, 24), label_header = "**Month {time}**") %>%
add_p() %>%
add_n()
```
```{r gtsummary_print2, include = FALSE}
# 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")
```
```{r out.width = "70%", echo = FALSE}
# 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](https://mskcc-epi-bio.github.io/tidycmprsk/CODE_OF_CONDUCT.html).
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("[@{.}](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`.