Function for creating automatic matches based on age and sex
Source:R/cdm_connector_setup.R
createControlCohortMatching.RdFunction for creating automatic matches based on age and sex
Value
A data frame representing the matched control cohort. The returned table contains cohort_definition_id, subject_id, cohort_start_date, and cohort_end_date columns, with one row per matched control interval aligned to the target cohort follow-up logic.
Examples
# \donttest{
if (requireNamespace("CDMConnector", quietly = TRUE) &&
requireNamespace("DBI", quietly = TRUE) &&
requireNamespace("duckdb", quietly = TRUE) &&
nzchar(Sys.getenv("EUNOMIA_DATA_FOLDER")) &&
isTRUE(tryCatch(
CDMConnector::eunomiaIsAvailable("GiBleed"),
error = function(...) FALSE
))) {
pathToJSON <- system.file(
"example", "example_json", "diclofenac",
package = "CohortContrast"
)
con <- DBI::dbConnect(
duckdb::duckdb(),
dbdir = CDMConnector::eunomiaDir("GiBleed")
)
cdm <- CDMConnector::cdmFromCon(
con = con,
cdmName = "eunomia",
cdmSchema = "main",
writeSchema = "main"
)
targetTable <- cohortFromJSON(pathToJSON = pathToJSON, cdm = cdm)
controlTable <- createControlCohortMatching(
cdm = cdm,
targetTable = targetTable,
ratio = 1
)
head(controlTable)
DBI::dbDisconnect(con, shutdown = TRUE)
}
# }