| Title: | Cohort-Based Single-Event Survival Utilities |
| Version: | 0.1.0 |
| Description: | Tools to build single-event survival datasets from "OMOP CDM" cohorts and estimate survival outcomes. The package supports Kaplan-Meier, Cox proportional hazards, and parametric accelerated-failure-time models, with optional stratification by gender and age groups. |
| License: | Apache License (== 2.0) |
| Imports: | DatabaseConnector, ggsurvfit, SqlRender, survival |
| Suggests: | Eunomia, knitr, rmarkdown, testthat (≥ 3.0.0) |
| VignetteBuilder: | knitr |
| Config/testthat/edition: | 3 |
| Encoding: | UTF-8 |
| RoxygenNote: | 7.3.2 |
| NeedsCompilation: | no |
| Packaged: | 2026-03-31 09:53:41 UTC; AlexanderAleksiayuk |
| Author: | Alexander Alexeyuk [aut, cre] |
| Maintainer: | Alexander Alexeyuk <AlexanderAlexeyuk@gmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-04-03 15:30:17 UTC |
Build a nested CASE-WHEN censor expression
Description
Build a nested CASE-WHEN censor expression
Usage
.buildCensorExpression(
censorOnCohortExit,
hasCensorDate,
hasFollowUpLimit,
followUpDays
)
Drop a vector of temp tables (best-effort, errors silenced)
Description
Drop a vector of temp tables (best-effort, errors silenced)
Usage
.dropTempTables(connection, dbms, tempEmulationSchema, tables)
Execute pre-rendered SQL statements and return the final result set
Description
Execute pre-rendered SQL statements and return the final result set
Usage
.executeSurvivalSql(
connection,
sql,
dbms,
tempEmulationSchema,
hasChunking,
chunkSize,
tempResult
)
Generate unique temp-table names for a single run
Description
Generate unique temp-table names for a single run
Usage
.generateTempNames()
Resolve DBMS from a DatabaseConnector connection
Description
Resolve DBMS from a DatabaseConnector connection
Usage
.getDbms(connection)
Return the parameterised SQL template
Description
Age / gender columns are included only when the corresponding
@include_age / @include_gender flags are TRUE.
The person-table JOIN is included when @include_demographics is TRUE.
Usage
.getSurvivalSqlTemplate()
Validate survival-specific inputs
Description
Validate survival-specific inputs
Usage
.validateSurvivalInputs(
outcomeDateVariable,
chunkSize,
outcomeWashout,
minDaysToEvent,
followUpDays
)
Calculate survival data for a cohort
Description
Calculate survival data for a cohort
Usage
addCohortSurvival(
connection,
cdmDatabaseSchema,
cohortDatabaseSchema,
targetCohortTable,
targetCohortId,
outcomeCohortTable,
outcomeCohortId = 1,
outcomeDatabaseSchema = cohortDatabaseSchema,
outcomeDateVariable = "cohort_start_date",
outcomeWashout = Inf,
minDaysToEvent = 0,
censorOnCohortExit = FALSE,
censorOnDate = NULL,
followUpDays = Inf,
includeAge = FALSE,
includeGender = FALSE,
observationPeriodTable = "observation_period",
tempEmulationSchema = NULL,
chunkSize = NULL,
addDay = FALSE
)
Arguments
connection |
DatabaseConnector connection object |
cdmDatabaseSchema |
Schema containing CDM tables |
cohortDatabaseSchema |
Schema containing cohort tables |
targetCohortTable |
Name of the target cohort table |
targetCohortId |
ID of the target cohort |
outcomeCohortTable |
Name of the outcome cohort table |
outcomeCohortId |
ID of the outcome cohort (default: 1) |
outcomeDateVariable |
Date variable for outcome ("cohort_start_date" or "cohort_end_date") |
outcomeWashout |
Washout period in days (default: Inf for no washout) |
minDaysToEvent |
Minimum days between cohort entry and outcome event (default: 0) |
censorOnCohortExit |
Whether to censor at cohort exit (default: FALSE) |
censorOnDate |
Specific date to censor at (default: NULL) |
followUpDays |
Maximum follow-up days (default: Inf) |
includeAge |
Whether to include age_years in the output (default: FALSE) |
includeGender |
Whether to include gender in the output (default: FALSE) |
observationPeriodTable |
Name of observation period table (default: "observation_period") |
tempEmulationSchema |
Schema for temp table emulation (default: NULL) |
chunkSize |
Optional chunk size for large cohorts (default: NULL) |
addDay |
Logical; add one day to the outcome date? (default: FALSE) |
Value
Data frame with columns subject_id, time, status
and optionally age_years and/or gender.
Kaplan–Meier survival by simple strata (gender and/or age groups)
Description
Compute Kaplan–Meier (KM) survival curves overall and, optionally, by simple
strata derived from an existing gender column and/or an age_group built
from list-of-range breaks using age_years. Results are returned per stratum
plus an "overall" entry. Additionally, log-rank tests (overall and
pairwise) are computed when strata are specified.
Usage
singleEventSurvival(
survivalData,
timeScale = "days",
model = "km",
covariates = NULL,
strata = NULL,
ageBreaks = list(c(0, 18), c(19, 45), c(46, 65), c(66, Inf)),
times = NULL,
probs = c(0.75, 0.5, 0.25),
confInt = 0.95,
confType = "log"
)
Arguments
survivalData |
A
|
timeScale |
One of |
model |
Survival estimator to fit. One of |
covariates |
Optional character vector of covariate column names used
in Cox and parametric models. Ignored for |
strata |
Optional character vector of stratifying variables. Allowed:
|
ageBreaks |
A list of numeric length-2 vectors defining age ranges for
auto-stratification, e.g.
|
times |
Reserved for future enhancements; currently unused. |
probs |
Numeric vector of probabilities used to extract quantiles from
KM curves. Default is |
confInt |
Numeric confidence level for KM intervals (e.g., |
confType |
Character string for KM CI type, one of |
Details
Input follow-up
timeis supplied in days and internally rescaled to the requestedtimeScalefor reporting ("days","weeks","months","years").If
"age_group"is included instrata, you must provide anage_yearscolumn. Age-group labels are generated fromageBreaks(e.g.,0-18,19-45,46-65,66+), where each element is a numeric rangec(min_age, max_age). UseInffor open-ended upper bounds.Stratification is simple: groups are created from observed levels of
genderand/or derivedage_group. If both are requested, they are handled separately (gender OR age_group), not jointly. A one-sample KM curve is fit for each non-empty group, plus an"overall"curve for the full data.Confidence intervals are controlled by
confTypeandconfIntand are passed tosurvival::survfit().The
modelargument controls which survival estimator is fitted:-
"km": non-parametric Kaplan–Meier estimate viaggsurvfit::survfit(). -
"cox": Cox PH model viasurvival::coxph()+survival::survfit(). Without covariates the Breslow baseline hazard is used. When covariates are provided, the survival curve is evaluated at the covariate means. -
"weibull","exponential","lognormal","loglogistic": AFT parametric models viasurvival::survreg(). S(t) is evaluated analytically at observed event times. Pointwise CIs are not available for parametric models (lower/upperareNA).
-
-
covariatesis used only for Cox and parametric models. -
timesandprobscontrol quantile extraction;probsdefaults toc(0.75, 0.5, 0.25)(q75, median, q25). When strata are specified, a log-rank test is performed to compare survival curves across groups within each stratifier (gender and/or age_group). The overall test and pairwise tests are included in the returned object as tibbles.
Value
A list of class singleEventSurvival. See Returned object.
Returned object
A list of class singleEventSurvival. Elements include:
Per-stratum entries named like
"gender=F","gender=M","age_group=18-44", etc., and an"overall"element.
Each stratum element contains:
-
data: a tibble with KM step data:time,n_risk,n_event,n_censor,survival,std_err, optionallower,upper(whenconfInt> 0), and derivedhazard,cum_hazard,cum_event,cum_censor. -
summary: a list withn,events,censored,medianSurvival,q25Survival,q75Survival,meanSurvival, andtimeScale.
Additionally, if gender is in strata, a logrank_test_gender element
is included; if age_group is in strata, a logrank_test_age_group
element is included. Each contains:
-
testType:"overall"or"pairwise" -
stratum1,stratum2: labels of compared strata -
chisq: chi-square test statistic -
df: degrees of freedom -
pvalue: p-value for the test