| Title: | Estimate Survival from Common Data Model Cohorts |
|---|---|
| Description: | Estimate survival using data mapped to the Observational Medical Outcomes Partnership common data model. Survival can be estimated based on user-defined study cohorts. |
| Authors: | Kim López-Güell [aut, cre] (ORCID: <https://orcid.org/0000-0002-8462-8668>), Edward Burn [aut] (ORCID: <https://orcid.org/0000-0002-9286-1128>), Martí Català [aut] (ORCID: <https://orcid.org/0000-0003-3308-9905>), Xintong Li [aut] (ORCID: <https://orcid.org/0000-0002-6872-5804>), Danielle Newby [aut] (ORCID: <https://orcid.org/0000-0002-3001-1478>), Nuria Mercade-Besora [aut] (ORCID: <https://orcid.org/0009-0006-7948-3747>) |
| Maintainer: | Kim López-Güell <[email protected]> |
| License: | Apache License (>= 2) |
| Version: | 1.1.0 |
| Built: | 2026-05-14 07:55:58 UTC |
| Source: | https://github.com/darwin-eu/cohortsurvival |
Add survival information to a cohort table
addCohortSurvival( x, cdm, outcomeCohortTable, outcomeCohortId = 1, outcomeDateVariable = "cohort_start_date", outcomeWashout = Inf, censorOnCohortExit = FALSE, censorOnDate = NULL, followUpDays = Inf, name = NULL )addCohortSurvival( x, cdm, outcomeCohortTable, outcomeCohortId = 1, outcomeDateVariable = "cohort_start_date", outcomeWashout = Inf, censorOnCohortExit = FALSE, censorOnDate = NULL, followUpDays = Inf, name = NULL )
x |
cohort table to add survival information |
cdm |
CDM reference |
outcomeCohortTable |
The outcome cohort table of interest. |
outcomeCohortId |
ID of event cohorts to include. Only one outcome (and so one ID) can be considered. It can either be a cohort_definition_id value or a cohort_name. |
outcomeDateVariable |
Variable containing date of outcome event |
outcomeWashout |
Washout time in days for the outcome. If an individual has an outcome during the washout period, status and time will be set to NA |
censorOnCohortExit |
If TRUE, an individual's follow up will be censored at their cohort exit |
censorOnDate |
if not NULL, an individual's follow up will be censored at the given date |
followUpDays |
Number of days to follow up individuals (lower bound 1, upper bound Inf) |
name |
Name of the new table, if NULL a temporary table is returned. |
Two additional columns will be added to x. The "time" column will contain number of days to censoring. The "status" column will indicate whether the patient had the event (value: 1), or did not have the event (value: 0)
cdm <- mockMGUS2cdm() cdm$mgus_diagnosis <- cdm$mgus_diagnosis |> addCohortSurvival( cdm = cdm, outcomeCohortTable = "death_cohort", outcomeCohortId = 1 )cdm <- mockMGUS2cdm() cdm$mgus_diagnosis <- cdm$mgus_diagnosis |> addCohortSurvival( cdm = cdm, outcomeCohortTable = "death_cohort", outcomeCohortId = 1 )
A tidy implementation of the summarised_characteristics object.
asSurvivalResult(result)asSurvivalResult(result)
result |
A summarised_characteristics object. |
A tibble with a tidy version of the summarised_characteristics object.
cdm <- mockMGUS2cdm() surv <- estimateSingleEventSurvival( cdm = cdm, targetCohortTable = "mgus_diagnosis", targetCohortId = 1, outcomeCohortTable = "death_cohort", outcomeCohortId = 1, eventGap = 7 ) |> asSurvivalResult()cdm <- mockMGUS2cdm() surv <- estimateSingleEventSurvival( cdm = cdm, targetCohortTable = "mgus_diagnosis", targetCohortId = 1, outcomeCohortTable = "death_cohort", outcomeCohortId = 1, eventGap = 7 ) |> asSurvivalResult()
Variables that can be used for faceting and colouring survival plots
availableSurvivalGrouping(result, varying = FALSE)availableSurvivalGrouping(result, varying = FALSE)
result |
Survival results |
varying |
If FALSE (default), only variables with non-unique values will be returned, otherwise all available variables will be returned. |
cdm <- mockMGUS2cdm() surv <- estimateSingleEventSurvival(cdm, targetCohortTable = "mgus_diagnosis", outcomeCohortTable = "death_cohort") availableSurvivalGrouping(surv)cdm <- mockMGUS2cdm() surv <- estimateSingleEventSurvival(cdm, targetCohortTable = "mgus_diagnosis", outcomeCohortTable = "death_cohort") availableSurvivalGrouping(surv)
Estimate survival for a given event and competing risk of interest using cohorts in the OMOP Common Data Model
estimateCompetingRiskSurvival( cdm, targetCohortTable, outcomeCohortTable, competingOutcomeCohortTable, targetCohortId = NULL, outcomeCohortId = NULL, outcomeDateVariable = "cohort_start_date", outcomeWashout = Inf, competingOutcomeCohortId = NULL, competingOutcomeDateVariable = "cohort_start_date", competingOutcomeWashout = Inf, censorOnCohortExit = FALSE, censorOnDate = NULL, followUpDays = Inf, strata = NULL, eventGap = 30, estimateGap = 1, restrictedMeanFollowUp = NULL, minimumSurvivalDays = 1 )estimateCompetingRiskSurvival( cdm, targetCohortTable, outcomeCohortTable, competingOutcomeCohortTable, targetCohortId = NULL, outcomeCohortId = NULL, outcomeDateVariable = "cohort_start_date", outcomeWashout = Inf, competingOutcomeCohortId = NULL, competingOutcomeDateVariable = "cohort_start_date", competingOutcomeWashout = Inf, censorOnCohortExit = FALSE, censorOnDate = NULL, followUpDays = Inf, strata = NULL, eventGap = 30, estimateGap = 1, restrictedMeanFollowUp = NULL, minimumSurvivalDays = 1 )
cdm |
CDM reference |
targetCohortTable |
The target cohort table of interest. |
outcomeCohortTable |
The outcome cohort table of interest. |
competingOutcomeCohortTable |
The competing outcome cohort table of interest. |
targetCohortId |
Target cohorts to include. It can either be a cohort_definition_id value or a cohort_name. Multiple ids are allowed. |
outcomeCohortId |
Outcome cohorts to include. It can either be a cohort_definition_id value or a cohort_name. Multiple ids are allowed. |
outcomeDateVariable |
Variable containing date of outcome event |
outcomeWashout |
Washout time in days for the outcome |
competingOutcomeCohortId |
Competing outcome cohorts to include. It can either be a cohort_definition_id value or a cohort_name. Multiple ids are allowed. |
competingOutcomeDateVariable |
Variable containing date of competing outcome event |
competingOutcomeWashout |
Washout time in days for the competing outcome |
censorOnCohortExit |
If TRUE, an individual's follow up will be censored at their cohort exit |
censorOnDate |
if not NULL, an individual's follow up will be censored at the given date |
followUpDays |
Number of days to follow up individuals (lower bound 1, upper bound Inf) |
strata |
strata |
eventGap |
Days between time points for which to report survival events, which are grouped into the specified intervals. |
estimateGap |
Days between time points for which to report survival estimates. First day will be day zero with risk estimates provided for times up to the end of follow-up, with a gap in days equivalent to eventGap. |
restrictedMeanFollowUp |
number of days of follow-up to take into account when calculating restricted mean for all cohorts |
minimumSurvivalDays |
Minimum number of days required for the main cohort to have survived |
tibble with survival information for desired cohort, including: time, people at risk, survival probability, cumulative incidence, 95 CIs, strata and outcome. A tibble with the number of events is outputted as an attribute of the output
cdm <- mockMGUS2cdm() surv <- estimateCompetingRiskSurvival( cdm = cdm, targetCohortTable = "mgus_diagnosis", targetCohortId = 1, outcomeCohortTable = "progression", outcomeCohortId = 1, competingOutcomeCohortTable = "death_cohort", competingOutcomeCohortId = 1, eventGap = 7 )cdm <- mockMGUS2cdm() surv <- estimateCompetingRiskSurvival( cdm = cdm, targetCohortTable = "mgus_diagnosis", targetCohortId = 1, outcomeCohortTable = "progression", outcomeCohortId = 1, competingOutcomeCohortTable = "death_cohort", competingOutcomeCohortId = 1, eventGap = 7 )
Estimate survival for a given event of interest using cohorts in the OMOP Common Data Model
estimateSingleEventSurvival( cdm, targetCohortTable, outcomeCohortTable, targetCohortId = NULL, outcomeCohortId = NULL, outcomeDateVariable = "cohort_start_date", outcomeWashout = Inf, censorOnCohortExit = FALSE, censorOnDate = NULL, followUpDays = Inf, strata = NULL, eventGap = 30, estimateGap = 1, restrictedMeanFollowUp = NULL, minimumSurvivalDays = 1 )estimateSingleEventSurvival( cdm, targetCohortTable, outcomeCohortTable, targetCohortId = NULL, outcomeCohortId = NULL, outcomeDateVariable = "cohort_start_date", outcomeWashout = Inf, censorOnCohortExit = FALSE, censorOnDate = NULL, followUpDays = Inf, strata = NULL, eventGap = 30, estimateGap = 1, restrictedMeanFollowUp = NULL, minimumSurvivalDays = 1 )
cdm |
CDM reference |
targetCohortTable |
targetCohortTable |
outcomeCohortTable |
The outcome cohort table of interest. |
targetCohortId |
Target cohorts to include. It can either be a cohort_definition_id value or a cohort_name. Multiple ids are allowed. |
outcomeCohortId |
Outcome cohorts to include. It can either be a cohort_definition_id value or a cohort_name. Multiple ids are allowed. |
outcomeDateVariable |
Variable containing date of outcome event |
outcomeWashout |
Washout time in days for the outcome |
censorOnCohortExit |
If TRUE, an individual's follow up will be censored at their cohort exit |
censorOnDate |
if not NULL, an individual's follow up will be censored at the given date |
followUpDays |
Number of days to follow up individuals (lower bound 1, upper bound Inf) |
strata |
strata |
eventGap |
Days between time points for which to report survival events, which are grouped into the specified intervals. |
estimateGap |
Days between time points for which to report survival estimates. First day will be day zero with risk estimates provided for times up to the end of follow-up, with a gap in days equivalent to eventGap. |
restrictedMeanFollowUp |
number of days of follow-up to take into account when calculating restricted mean for all cohorts |
minimumSurvivalDays |
Minimum number of days required for the main cohort to have survived |
tibble with survival information for desired cohort, including: time, people at risk, survival probability, cumulative incidence, 95 CIs, strata and outcome. A tibble with the number of events is outputted as an attribute of the output
cdm <- mockMGUS2cdm() surv <- estimateSingleEventSurvival( cdm = cdm, targetCohortTable = "mgus_diagnosis", targetCohortId = 1, outcomeCohortTable = "death_cohort", outcomeCohortId = 1, eventGap = 7 )cdm <- mockMGUS2cdm() surv <- estimateSingleEventSurvival( cdm = cdm, targetCohortTable = "mgus_diagnosis", targetCohortId = 1, outcomeCohortTable = "death_cohort", outcomeCohortId = 1, eventGap = 7 )
Create mock CDM reference with survival::mgus2 dataset
mockMGUS2cdm()mockMGUS2cdm()
CDM reference containing data from the survival::mgus2 dataset
cdm <- mockMGUS2cdm() cdm$personcdm <- mockMGUS2cdm() cdm$person
It provides a list of allowed inputs for .option argument in tableSurvival and their given default value.
optionsTableSurvival()optionsTableSurvival()
The default .options named list.
{ optionsTableSurvival() }{ optionsTableSurvival() }
Plot survival results
plotSurvival( result, ribbon = TRUE, facet = NULL, colour = NULL, cumulativeFailure = FALSE, riskTable = FALSE, riskInterval = 30, logLog = FALSE, timeScale = "days", style = NULL )plotSurvival( result, ribbon = TRUE, facet = NULL, colour = NULL, cumulativeFailure = FALSE, riskTable = FALSE, riskInterval = 30, logLog = FALSE, timeScale = "days", style = NULL )
result |
Survival results |
ribbon |
If TRUE, the plot will join points using a ribbon |
facet |
Variables to use for facets |
colour |
Variables to use for colours |
cumulativeFailure |
whether to plot the cumulative failure probability instead of the survival probability |
riskTable |
Whether to print risk table below the plot |
riskInterval |
Interval of time to print risk table below the plot |
logLog |
If TRUE, the survival probabilities are transformed using the log-log formula |
timeScale |
The scale of time in the x-axis. Can be "days", "months", or "years" |
style |
A character string defining the visual theme to apply to the plot. You can set this to NULL to apply the standard ggplot2 default style, or provide a name for one of the package's pre-defined styles. Refer to the plotStyle() function for all available style pre-defined themes. For further customization, you can always modify the returned ggplot object directly. |
A plot of survival probabilities over time
cdm <- mockMGUS2cdm() surv <- estimateSingleEventSurvival(cdm, targetCohortTable = "mgus_diagnosis", outcomeCohortTable = "death_cohort") plotSurvival(surv)cdm <- mockMGUS2cdm() surv <- estimateSingleEventSurvival(cdm, targetCohortTable = "mgus_diagnosis", outcomeCohortTable = "death_cohort") plotSurvival(surv)
Table with survival events
riskTable( x, eventGap = NULL, header = c("estimate"), type = "gt", groupColumn = NULL, hide = c("result_id", "estimate_type"), style = NULL, .options = list() )riskTable( x, eventGap = NULL, header = c("estimate"), type = "gt", groupColumn = NULL, hide = c("result_id", "estimate_type"), style = NULL, .options = list() )
x |
Result from estimateSingleEventSurvival or estimateCompetingRiskSurvival. |
eventGap |
Event gap defining the times at which to report the risk table information. Must be one of the eventGap inputs used for the estimation function. If NULL, all available are reported. |
header |
A vector specifying the elements to include in the header. The order of elements matters, with the first being the topmost header. Elements in header can be:
|
type |
Character string specifying the desired output table format.
See |
groupColumn |
Columns to use as group labels, to see options use
*tidy: The tidy format applied to column names replaces "_" with a space and
converts to sentence case. Use |
hide |
Columns to drop from the output table. By default, |
style |
Defines the visual formatting of the table. This argument can be provided in one of the following ways:
|
.options |
A named list with additional formatting options.
|
A tibble containing the risk table information (n_risk, n_events, n_censor) for all times within the event gap specified.
cdm <- mockMGUS2cdm() surv <- estimateSingleEventSurvival(cdm, targetCohortTable = "mgus_diagnosis", outcomeCohortTable = "death_cohort") riskTable(surv)cdm <- mockMGUS2cdm() surv <- estimateSingleEventSurvival(cdm, targetCohortTable = "mgus_diagnosis", outcomeCohortTable = "death_cohort") riskTable(surv)
Table with survival summary
tableSurvival( x, times = NULL, timeScale = "days", header = c("estimate"), estimates = c("median_survival", "restricted_mean_survival"), type = "gt", groupColumn = NULL, hide = c("result_id", "estimate_type"), style = NULL, .options = list() )tableSurvival( x, times = NULL, timeScale = "days", header = c("estimate"), estimates = c("median_survival", "restricted_mean_survival"), type = "gt", groupColumn = NULL, hide = c("result_id", "estimate_type"), style = NULL, .options = list() )
x |
Result from estimateSingleEventSurvival or estimateCompetingRiskSurvival |
times |
Times at which to report survival in the summary table |
timeScale |
Time unit to report survival in: days, months or years |
header |
A vector specifying the elements to include in the header. The order of elements matters, with the first being the topmost header. Elements in header can be:
|
estimates |
Character vector specifying which estimates to include in the table. Options include: "median_survival", "restricted_mean_survival", "q0_survival", "q05_survival", "q25_survival", "q75_survival", "q95_survival", "q100_survival". By default it includes c("median_survival", "restricted_mean_survival"). |
type |
Character string specifying the desired output table format.
See |
groupColumn |
Columns to use as group labels, to see options use
*tidy: The tidy format applied to column names replaces "_" with a space and
converts to sentence case. Use |
hide |
Columns to drop from the output table. By default, |
style |
Defines the visual formatting of the table. This argument can be provided in one of the following ways:
|
.options |
A named list with additional formatting options.
|
A tibble containing a summary of observed survival in the required units
cdm <- mockMGUS2cdm() surv <- estimateSingleEventSurvival(cdm, targetCohortTable = "mgus_diagnosis", outcomeCohortTable = "death_cohort") tableSurvival(surv, times = c(50,100,365))cdm <- mockMGUS2cdm() surv <- estimateSingleEventSurvival(cdm, targetCohortTable = "mgus_diagnosis", outcomeCohortTable = "death_cohort") tableSurvival(surv, times = c(50,100,365))
Display the attrition of a survival result in a visual table
tableSurvivalAttrition( result, type = "gt", header = "variable_name", groupColumn = c("cdm_name", "target_cohort", "variable_level"), hide = c("estimate_name"), style = NULL, .options = list() )tableSurvivalAttrition( result, type = "gt", header = "variable_name", groupColumn = c("cdm_name", "target_cohort", "variable_level"), hide = c("estimate_name"), style = NULL, .options = list() )
result |
A summarised_result object obtained either from
|
type |
Character string specifying the desired output table format.
See |
header |
A vector specifying the elements to include in the header. The order of elements matters, with the first being the topmost header. Elements in header can be:
|
groupColumn |
Columns to use as group labels, to see options use
*tidy: The tidy format applied to column names replaces "_" with a space and
converts to sentence case. Use |
hide |
Columns to drop from the output table. By default, |
style |
Defines the visual formatting of the table. This argument can be provided in one of the following ways:
|
.options |
A named list with additional formatting options.
|
A visual table
library(CohortSurvival) cdm <- mockMGUS2cdm() surv <- estimateSingleEventSurvival( cdm = cdm, targetCohortTable = "mgus_diagnosis", outcomeCohortTable = "death_cohort" ) tableSurvivalAttrition(surv)library(CohortSurvival) cdm <- mockMGUS2cdm() surv <- estimateSingleEventSurvival( cdm = cdm, targetCohortTable = "mgus_diagnosis", outcomeCohortTable = "death_cohort" ) tableSurvivalAttrition(surv)
Table with survival events
tableSurvivalEvents( x, eventGap = NULL, header = c("estimate"), type = "gt", groupColumn = NULL, hide = c("result_id", "estimate_type"), style = NULL, .options = list() )tableSurvivalEvents( x, eventGap = NULL, header = c("estimate"), type = "gt", groupColumn = NULL, hide = c("result_id", "estimate_type"), style = NULL, .options = list() )
x |
Result from estimateSingleEventSurvival or estimateCompetingRiskSurvival. |
eventGap |
Event gap defining the times at which to report the risk table information. Must be one of the eventGap inputs used for the estimation function. If NULL, all available are reported. |
header |
A vector specifying the elements to include in the header. The order of elements matters, with the first being the topmost header. Elements in header can be:
|
type |
Character string specifying the desired output table format.
See |
groupColumn |
Columns to use as group labels, to see options use
*tidy: The tidy format applied to column names replaces "_" with a space and
converts to sentence case. Use |
hide |
Columns to drop from the output table. By default, |
style |
Defines the visual formatting of the table. This argument can be provided in one of the following ways:
|
.options |
A named list with additional formatting options.
|
A tibble containing the risk table information (n_risk, n_events, n_censor) for all times within the event gap specified.
cdm <- mockMGUS2cdm() surv <- estimateSingleEventSurvival(cdm, targetCohortTable = "mgus_diagnosis", outcomeCohortTable = "death_cohort") tableSurvivalEvents(surv)cdm <- mockMGUS2cdm() surv <- estimateSingleEventSurvival(cdm, targetCohortTable = "mgus_diagnosis", outcomeCohortTable = "death_cohort") tableSurvivalEvents(surv)