getSccRiskWindowStats: Get Self-Controlled Cohort Risk Window Statistics

View source: R/RiskWindows.R

getSccRiskWindowStatsR Documentation

Get Self-Controlled Cohort Risk Window Statistics

Description

Compute statistics from risk windows.

Usage

getSccRiskWindowStats(
  connection,
  outcomeDatabaseSchema,
  databaseId,
  tempEmulationSchema = getOption("sqlRenderTempEmulationSchema"),
  outcomeIds = NULL,
  outcomeTable = "condition_era",
  firstOutcomeOnly = TRUE,
  resultsDatabaseSchema = NULL,
  riskWindowsTable = "#risk_windows",
  resultExportPath = "scc_result",
  analysisId = 1,
  resultExportManager = ResultModelManager::createResultExportManager(tableSpecification
    = getResultsDataModelSpecifications(), exportDir = resultExportPath, databaseId =
    databaseId)
)

Arguments

connection

DatabaseConnector connection instance

outcomeDatabaseSchema

The name of the database schema that is the location where the data used to define the outcome cohorts is available. If exposureTable = CONDITION_ERA, exposureDatabaseSchema is not used by assumed to be cdmSchema. Requires read permissions to this database.

databaseId

Unique identifier for database - required

tempEmulationSchema

Some database platforms like Oracle and Impala do not truly support temp tables. To emulate temp tables, provide a schema with write privileges where temp tables can be created.

outcomeIds

The condition_concept_ids or cohort_definition_ids of the outcomes of interest. If empty, all the outcomes in the outcome table will be included.

outcomeTable

The tablename that contains the outcome cohorts. If outcomeTable <> CONDITION_OCCURRENCE, then expectation is outcomeTable has format of COHORT table: COHORT_DEFINITION_ID, SUBJECT_ID, COHORT_START_DATE, COHORT_END_DATE.

firstOutcomeOnly

If TRUE, only use first occurrence of each condition concept id for each person.

resultsDatabaseSchema

Schema to oputput results to. Ignored if resultsTable and riskWindowsTable are temporary.

riskWindowsTable

String: optionally store the risk windows in a (non-temporary) table.

resultExportPath

Folder where result files are exported

analysisId

An integer unique to this analysis

resultExportManager

ResultModelManager::ResultExportManager instance - customize this to implement an alternative mechanism for exporting results

Details

Requires a risk window table to be created first with 'runSccRiskWindows'

Value

list containing data frames: treatmentTimeDistribution, timeToOutcomeDistribution, timeToOutcomeDistributionExposed, timeToOutcomeDistributionUnexposed

Examples


if (interactive()) {
# First, create the risk windows table
connectionDetails <- Eunomia::getEunomiaConnectionDetails()
connection <- DatabaseConnector::connect(connectionDetails)
riskWindowsTable <- "computed_risk_windows"
runSccRiskWindows(connection,
                  cdmDatabaseSchema = "main",
                  exposureIds = c(1102527, 1125315),
                  resultsDatabaseSchema = "main",
                  riskWindowsTable = riskWindowsTable,
                  exposureTable = "drug_era")
# Get stats based on outcomes of interest
tarStats <- getSccRiskWindowStats(connection,
                                  outcomeDatabaseSchema = "main",
                                  databaseId = "Eunomia",
                                  resultsDatabaseSchema = "main",
                                  riskWindowsTable = riskWindowsTable,
                                  outcomeTable = "condition_era",
                                  outcomeIds = 192671)
DatabaseConnector::disconnect(connection)
}


SelfControlledCohort documentation built on June 17, 2026, 5:07 p.m.