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 data.frame with required columns:

  • subject_id (unique id)

  • time (numeric follow-up in days; finite)

  • status (0/1; 1 = event) Optional columns for stratification/age grouping: gender, age_years. Additional columns may be present but are currently unused.

timeScale

One of "days", "weeks", "months", or "years". Used only to scale the reported time axis; input time is assumed to be days.

model

Survival estimator to fit. One of "km" (Kaplan–Meier), "cox" (Cox PH, baseline hazard), "weibull", "exponential", "lognormal", "loglogistic" (AFT parametric models via survival::survreg()).

covariates

Optional character vector of covariate column names used in Cox and parametric models. Ignored for model = "km".

strata

Optional character vector of stratifying variables. Allowed: "gender", "age_group". If both are supplied, they are applied independently (gender OR age_group).

ageBreaks

A list of numeric length-2 vectors defining age ranges for auto-stratification, e.g. list(c(0, 18), c(19, 45), c(46, 65), c(66, Inf)) -> 0-18, 19-45, 46-65, ⁠66+⁠. Used only if "age_group" is in strata.

times

Reserved for future enhancements; currently unused.

probs

Numeric vector of probabilities used to extract quantiles from KM curves. Default is c(0.75, 0.5, 0.25).

confInt

Numeric confidence level for KM intervals (e.g., 0.95); passed as conf.int to survival::survfit().

confType

Character string for KM CI type, one of "log", "log-log", "plain", "arcsin", "none"; passed as conf.type to survival::survfit().

Details

Value

A list of class singleEventSurvival. See Returned object.

Returned object

A list of class singleEventSurvival. Elements include:

Each stratum element contains:

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: