forked from darwin-eu/CohortSurvival
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME.Rmd
More file actions
146 lines (106 loc) · 4.42 KB
/
README.Rmd
File metadata and controls
146 lines (106 loc) · 4.42 KB
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
136
137
138
139
140
141
142
143
144
145
146
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
warning = FALSE, message = FALSE,
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# CohortSurvival <a href="https://darwin-eu.github.io/CohortSurvival/"><img src="man/figures/logo.png" alt="CohortSurvival website" align="right" height="138"/></a>
[](https://CRAN.R-project.org/package=CohortSurvival) [](https://app.codecov.io/github/darwin-eu/CohortSurvival?branch=main) [](https://github.com/darwin-eu/CohortSurvival/actions) [](https://lifecycle.r-lib.org/articles/stages.html)
CohortSurvival contains functions for extracting and summarising survival data using the OMOP common data model.
## Installation
You can install CohortSurvival like so:
```{r, eval=FALSE}
install.packages("CohortSurvival")
```
## Example usage
### Create a reference to data in the OMOP CDM format
The CohortSurvival package is designed to work with data in the OMOP CDM format, so our first step is to create a reference to the data using the CDMConnector package.
For this example we´ll use a cdm reference containing the MGUS2 dataset from the survival package (which we transformed into a set of OMOP CDM style cohort tables). The MGUS2 dataset contains survival data of 1341 sequential patients with monoclonal gammopathy of undetermined significance (MGUS). For more information see `?survival::mgus2`.
```{r}
library(CDMConnector)
library(CohortSurvival)
library(dplyr)
library(ggplot2)
cdm <- CohortSurvival::mockMGUS2cdm()
```
In our cdm reference we have three cohort tables of interest:
1) MGUS diagnosis cohort
```{r}
cdm$mgus_diagnosis |>
glimpse()
```
2) MGUS progression to multiple myeloma cohort
```{r}
cdm$progression |>
glimpse()
```
3) Death cohort
```{r}
cdm$death_cohort |>
glimpse()
```
### MGUS diagnosis to death
We can get survival estimates for death following MGUS diagnosis like so:
```{r}
MGUS_death <- estimateSingleEventSurvival(cdm,
targetCohortTable = "mgus_diagnosis",
outcomeCohortTable = "death_cohort"
)
MGUS_death |>
glimpse()
```
Now that we have our results, we can quickly create a plot summarising survival over time.
```{r}
plotSurvival(MGUS_death)
```
As well as estimating survival for our cohort overall, we can also estimate survival by strata. These strata are based on variables that have been added to our target cohort previously as columns.
```{r}
MGUS_death <- estimateSingleEventSurvival(cdm,
targetCohortTable = "mgus_diagnosis",
outcomeCohortTable = "death_cohort",
strata = list(c("age_group"),
c("sex"),
c("age_group", "sex"))
)
plotSurvival(MGUS_death,
colour = "strata_level",
facet= "strata_name")
```
## Estimating survival accounting for a competing risk
The package also allows to estimate survival of both an outcome and competing risk outcome together. We can then stratify, see information on events or summarise the estimates in the same way we did for the single event survival analysis.
```{r, fig.width=5}
MGUS_death_prog <- estimateCompetingRiskSurvival(cdm,
targetCohortTable = "mgus_diagnosis",
outcomeCohortTable = "progression",
competingOutcomeCohortTable = "death_cohort"
)
plotSurvival(MGUS_death_prog, cumulativeFailure = TRUE,
colour = "variable_level")
```
As with single event survival, we can stratify our competing risk analysis.
```{r}
MGUS_death_prog <- estimateCompetingRiskSurvival(cdm,
targetCohortTable = "mgus_diagnosis",
outcomeCohortTable = "progression",
competingOutcomeCohortTable = "death_cohort",
strata = list(c("age_group", "sex"))
)
plotSurvival(MGUS_death_prog |>
dplyr::filter(strata_name != "overall"),
cumulativeFailure = TRUE,
facet = "strata_level",
colour = "variable_level")
```
### Disconnect from the cdm database connection
```{r}
cdmDisconnect(cdm)
```
### Additional information
You can check additional functionality of the package on its [website](https://darwin-eu.github.io/CohortSurvival/).