Learn R Programming

SelfControlledCaseSeries

SelfControlledCaseSeries is part of HADES.

Introduction

SelfControlledCaseSeries is an R package for performing Self-Controlled Case Series (SCCS) analyses in an observational database in the OMOP Common Data Model.

Features

  • Extracts the necessary data from a database in OMOP Common Data Model format.
  • Optionally add seasonality using a spline function.
  • Optionally add age using a spline function.
  • Optionally add calendar time using a spline function.
  • Optionally correct for event-dependent censoring of the observation period.
  • Optionally add many covariates in one analysis (e.g. all drugs).
  • Options for constructing different types of covariates and risk windows, including pre-exposure windows (to capture contra-indications).
  • Optionally use regularization on all covariates except the outcome of interest.
  • Also provides the self-controlled risk interval design as a special case of the SCCS.
  • Includes diagnostics for all major assumptions of the SCCS design.

Example

sccsData <- getDbSccsData(
  connectionDetails = connectionDetails,
  cdmDatabaseSchema = cdmDatabaseSchema,
  outcomeIds = 192671,
  getDbSccsDataArgs = createGetDbSccsDataArgs(
    exposureIds = 1124300
  )
)

studyPop <- createStudyPopulation(
  sccsData = sccsData,
  outcomeId = 192671,
  createStudyPopulationArgs = createCreateStudyPopulationArgs(
    firstOutcomeOnly = FALSE,
    naivePeriod = 180
  )
)
 
  
covarDiclofenac = createEraCovariateSettings(
  label = "Exposure of interest",
  includeEraIds = 1124300,
  start = 0,
  end = 0,
  endAnchor = "era end"
)

sccsIntervalData <- createSccsIntervalData(
  studyPop,
  sccsData,
  createSccsIntervalDataArgs =  createCreateSccsIntervalDataArgs(
    eraCovariateSettings = covarDiclofenac
  )
)

model <- fitSccsModel(
  sccsIntervalData = sccsIntervalData,
  fitSccsModelArgs = createFitSccsModelArgs()
)

model
# SccsModel object
# 
# Outcome ID: 192671
# 
# Outcome count:
#        outcomeSubjects outcomeEvents outcomeObsPeriods
# 192671          272243        387158            274449
# 
# Estimates:
# # A tibble: 1 x 7
#   Name                                ID Estimate LB95CI UB95CI logRr seLogRr
#   <chr>                            <dbl>    <dbl>  <dbl>  <dbl> <dbl>   <dbl>
# 1 Exposure of interest: Diclofenac  1000     1.18   1.13   1.24 0.167  0.0230

Technology

SelfControlledCaseSeries is an R package, with some functions implemented in C++.

System Requirements

Requires R (version 4.1.0 or higher). Installation on Windows requires RTools. Libraries used in SelfControlledCaseSeries require Java.

Installation

  1. See the instructions here for configuring your R environment, including Java.

  2. In R, use the following commands to download and install SelfControlledCaseSeries:

install.packages("remotes")
remotes::install_github("ohdsi/SelfControlledCaseSeries")

User Documentation

Documentation can be found on the package website.

PDF versions of the documentation are also available:

Support

  • Developer questions/comments/feedback: OHDSI Forum
  • We use the GitHub issue tracker for all bugs/issues/enhancements

Contributing

Read here how you can contribute to this package.

License

SelfControlledCaseSeries is licensed under Apache License 2.0

Development

SelfControlledCaseSeries is being developed in R Studio.

Development status

Stable. Actively used in several projects.

Acknowledgements

  • This project is supported in part through the National Science Foundation grant IIS 1251151.
  • Part of the code is based on the SCCS package by Yonas Ghebremichael-Weldeselassie, Heather Whitaker, and Paddy Farrington.

Copy Link

Version

Install

install.packages('SelfControlledCaseSeries')

Version

6.0.0

License

Apache License 2.0

Issues

Pull Requests

Stars

Forks

Maintainer

Martijn Schuemie

Last Published

June 23rd, 2025

Functions in SelfControlledCaseSeries (6.0.0)

createSccsIntervalData

Create SCCS era data
createEraCovariateSettings

Create era covariate settings
getDiagnosticsSummary

Get a summary report of the analyses diagnostics
getDataMigrator

Get database migrations instance
createExposure

Create exposure definition
getFileReference

Get file reference
getDbSccsData

Load data for SCCS from the database
createSccsMultiThreadingSettings

Create SelfControlledCaseSeries multi-threading settings
createStudyPopulation

Create a study population
createSimulationRiskWindow

Create a risk window definition for simulation
createExposuresOutcome

Create a exposures-outcome combination.
createControlIntervalSettings

Create control interval settings
createFitSccsModelArgs

Create a parameter object for the function fitSccsModel
createSccsSimulationSettings

Create SCCS simulation settings
hasCalendarTimeEffect

Does the model contain an age effect?
isSccsData

Check whether an object is a SccsData object
hasSeasonality

Does the model contain an age effect?
isSccsIntervalData

Check whether an object is a SccsIntervalData object
fitSccsModel

Fit the SCCS model
getAttritionTable

Get the attrition table for a population
plotSeasonality

Plot the seasonality effect
plotAgeSpans

Plot the age ranges spanned by each observation period.
plotCalendarTimeSpans

Plot the calendar time ranges spanned by each observation period.
createGetDbSccsDataArgs

Create a parameter object for the function getDbSccsData
hasAgeEffect

Does the model contain an age effect?
createResultsDataModel

Create the results data model tables on a database server.
cyclicSplineDesign

Create a design matrix for a cyclic spline
exportToCsv

Export SCCSresults to CSV files
getResultsSummary

Get a summary report of the analyses results
loadSccsData

Load the cohort method data from a file
loadSccsIntervalData

Load the cohort method data from a file
plotCalendarTimeEffect

Plot the calendar time effect
migrateDataModel

Migrate Data model
plotAgeEffect

Plot the age effect
plotEventObservationDependence

Plot time from event to observation end for censored and uncensored time.
convertSccsAnalysesSpecificationsToJson

Convert SccsAnalysesSpecifications to JSON
createSccsAnalysis

Create a SelfControlledCaseSeries analysis specification
plotExposureCentered

Plot information centered around the start of exposure
plotEventToCalendarTime

Plot the ratio of observed to expected events over calendar time.
createSccsAnalysesSpecifications

Create full SCCS analysis specifications
createScriIntervalData

Create Self-Controlled Risk Interval (SCRI) era data
getResultsDataModelSpecifications

Get specifications for SelfControlledCaseSeries results data model
createSeasonalityCovariateSettings

Create seasonality settings
getModel

Output the full model
saveExposuresOutcomeList

Save a list of ExposuresOutcome to file
saveSccsAnalysisList

Save a list of SccsAnalysis to file
saveSccsData

Save the cohort method data to file
saveSccsIntervalData

Save the cohort method data to file
runSccsAnalyses

Run a list of analyses
loadExposuresOutcomeList

Load a list of ExposuresOutcome from file
uploadResults

Upload results to the database server.
loadSccsAnalysisList

Load a list of sccsAnalysis from file
simulateSccsData

Simulate SCCS data
computeTimeStability

Check stability of outcome rate over time
SccsData-class

SCCS Data
SelfControlledCaseSeries-package

SelfControlledCaseSeries: Self-Controlled Case Series
computePreExposureGainP

Compute P for pre-exposure risk gain
checkEventExposureIndependenceAssumption

Check diagnostic for event-dependent exposure
checkTimeStabilityAssumption

Check stability of outcome rate over time
computeMdrr

Compute the minimum detectable relative risk
SccsIntervalData-class

SCCS Interval Data
checkEventObservationIndependenceAssumption

Check diagnostic for event-dependent observation end
checkRareOutcomeAssumption

Check if rare outcome assumption is violated
createCalendarTimeCovariateSettings

Create calendar time settings
createAgeCovariateSettings

Create age covariate sesettings#' Create age covariate settings
convertJsonToSccsAnalysesSpecifications

Convert JSON to SccsAnalysesSpecifications
convertUntypedListToSccsAnalysesSpecifications

Convert untyped list to SccsAnalysesSpecifications
createDefaultSccsMultiThreadingSettings

Create default SelfControlledCaseSeries multi-threading settings
createCreateStudyPopulationArgs

Create a parameter object for the createStudyPopulation() function
createCreateScriIntervalDataArgs

Create a parameter object for the createScriIntervalData() function
createCreateSccsIntervalDataArgs

Create a parameter object for the createSccsIntervalData() function
createSccsDiagnosticThresholds

Create SCCS diagnostics thresholds