### Install CohortConstructor Development Version from GitHub Source: https://github.com/ohdsi/cohortconstructor/blob/main/README.md Install the latest development version of CohortConstructor from GitHub. Ensure the devtools package is installed first. ```r # install.packages("devtools") devtools::install_github("ohdsi/CohortConstructor") ``` -------------------------------- ### Install CohortConstructor from CRAN Source: https://github.com/ohdsi/cohortconstructor/blob/main/README.md Use this command to install the stable version of the CohortConstructor package from CRAN. ```r install.packages("CohortConstructor") ``` -------------------------------- ### Generate Concept-Based Fracture Cohort (Event Start Date Exit) Source: https://github.com/ohdsi/cohortconstructor/blob/main/README.md Create an initial cohort of individuals with fractures based on the defined codelist. The cohort exit date is set to the event start date. ```r cdm$fractures <- cdm |> conceptCohort(conceptSet = fx_codes, exit = "event_start_date", name = "fractures") ``` -------------------------------- ### View Cohort Count Source: https://github.com/ohdsi/cohortconstructor/blob/main/README.md Get the number of records and subjects for each cohort definition. This provides a summary of the cohort sizes. ```r cohortCount(cdm$fractures) |> glimpse() ``` -------------------------------- ### Create and Require Intersection with GI Bleed Cohort Source: https://github.com/ohdsi/cohortconstructor/blob/main/README.md Creates a 'gibleed' cohort based on a concept ID and then filters the 'fractures' cohort to exclude individuals who were in the 'gibleed' cohort within a specified window (-Inf to 0 days prior to fracture cohort start). ```r cdm$gibleed <- cdm |> conceptCohort(conceptSet = list("gibleed" = 192671L), name = "gibleed") cdm$fractures <- cdm$fractures |> requireCohortIntersect(targetCohortTable = "gibleed", intersections = 0, window = c(-Inf, 0)) ``` -------------------------------- ### Require Cohort Start Date within a Range Source: https://github.com/ohdsi/cohortconstructor/blob/main/README.md Filters the 'fractures' cohort to include only individuals whose cohort start date falls within the specified date range (January 1, 2000, to January 1, 2020). ```r cdm$fractures <- cdm$fractures |> requireInDateRange(dateRange = as.Date(c("2000-01-01", "2020-01-01"))) ``` -------------------------------- ### Get Candidate Codes for Fractures Source: https://github.com/ohdsi/cohortconstructor/blob/main/README.md Retrieve candidate concept IDs for 'hip fracture' and 'forearm fracture' from the CDM vocabulary. This function is part of the CodelistGenerator package. ```r library(CodelistGenerator) hip_fx_codes <- getCandidateCodes(cdm, "hip fracture") forearm_fx_codes <- getCandidateCodes(cdm, "forearm fracture") ``` -------------------------------- ### Pad Cohort End Date Source: https://github.com/ohdsi/cohortconstructor/blob/main/README.md Update the cohort to extend the exit date up to 180 days after the event start date. The exit date will not exceed the individual's observation period end date. ```r cdm$fractures <- cdm$fractures |> padCohortEnd(days = 180) ``` -------------------------------- ### Create Mock CDM Reference Source: https://github.com/ohdsi/cohortconstructor/blob/main/README.md Create a mock OMOP CDM reference object from a dataset. This is useful for testing and development with synthetic data. ```r cdm <- mockCdmFromDataset(datasetName = "GiBleed") ``` -------------------------------- ### Load Required R Packages Source: https://github.com/ohdsi/cohortconstructor/blob/main/README.md Load the necessary R packages for working with OMOP CDM data and CohortConstructor. ```r library(omopgenerics) library(omock) library(PatientProfiles) library(dplyr) library(CohortConstructor) library(CohortCharacteristics) ``` -------------------------------- ### View Cohort Settings Source: https://github.com/ohdsi/cohortconstructor/blob/main/README.md Inspect the settings associated with the created cohort, including cohort definition ID, name, CDM version, and vocabulary version. ```r settings(cdm$fractures) |> glimpse() ``` -------------------------------- ### View Cohort Settings and Count Source: https://github.com/ohdsi/cohortconstructor/blob/main/README.md Displays the settings and counts for the 'fractures' cohort, showing individual cohort definitions and their subject counts. ```r settings(cdm$fractures) #> # A tibble: 3 × 5 #> cohort_definition_id cohort_name cdm_version vocabulary_version gap #> #> 1 1 forearm_fracture 5.3 v5.0 18-JAN-19 NA #> 2 2 hip_fracture 5.3 v5.0 18-JAN-19 NA #> 3 3 any_fracture 0 cohortCount(cdm$fractures) #> # A tibble: 3 × 3 #> cohort_definition_id number_records number_subjects #> #> 1 1 569 510 #> 2 2 138 132 #> 3 3 707 611 ``` -------------------------------- ### View Attrition After Demographic Filters Source: https://github.com/ohdsi/cohortconstructor/blob/main/README.md Displays the attrition results after applying age and sex filters to the 'fractures' cohort. This helps visualize the impact of demographic restrictions. ```r attrition(cdm$fractures) |> filter(reason == "Age requirement: 40 to 65") |> glimpse() #> Rows: 3 #> Columns: 7 #> $ cohort_definition_id 1, 2, 3 #> $ number_records 64, 22, 86 #> $ number_subjects 62, 22, 83 #> $ reason_id 8, 8, 4 #> $ reason "Age requirement: 40 to 65", "Age requirement: 40… #> $ excluded_records 88, 40, 128 #> $ excluded_subjects 81, 38, 113 attrition(cdm$fractures) |> filter(reason == "Sex requirement: Female") |> glimpse() #> Rows: 3 #> Columns: 7 #> $ cohort_definition_id 1, 2, 3 #> $ number_records 37, 12, 49 #> $ number_subjects 36, 12, 48 #> $ reason_id 9, 9, 5 #> $ reason "Sex requirement: Female", "Sex requirement: Fema… #> $ excluded_records 27, 10, 37 #> $ excluded_subjects 26, 10, 35 ``` -------------------------------- ### Create New Codelist Source: https://github.com/ohdsi/cohortconstructor/blob/main/README.md Combine concept IDs for different fracture types into a new codelist object using the CodelistGenerator package. ```r fx_codes <- newCodelist(list("hip_fracture" = hip_fx_codes$concept_id, "forearm_fracture"= forearm_fx_codes$concept_id)) ``` -------------------------------- ### View Cohort Attrition Source: https://github.com/ohdsi/cohortconstructor/blob/main/README.md Examine the attrition table for the cohort, showing the number of records and subjects at each stage of cohort definition and any exclusions. ```r attrition(cdm$fractures) |> glimpse() ``` -------------------------------- ### Union Multiple Fracture Cohorts Source: https://github.com/ohdsi/cohortconstructor/blob/main/README.md Combines multiple existing fracture cohorts into a single 'any_fracture' cohort. Use 'keepOriginalCohorts = TRUE' to retain the individual fracture cohorts. ```r cdm$fractures <- unionCohorts(cdm$fractures, cohortName = "any_fracture", keepOriginalCohorts = TRUE, name ="fractures") ``` -------------------------------- ### View Updated Cohort Count After Date Restriction Source: https://github.com/ohdsi/cohortconstructor/blob/main/README.md Shows the updated cohort counts after applying the date range restriction. The 'glimpse()' function provides a detailed view of the tibble structure. ```r cohortCount(cdm$fractures) |> glimpse() #> Rows: 3 #> Columns: 3 #> $ cohort_definition_id 1, 2, 3 #> $ number_records 152, 62, 214 #> $ number_subjects 143, 60, 196 attrition(cdm$fractures) |> filter(reason == "cohort_start_date between 2000-01-01 & 2020-01-01") |> glimpse() #> Rows: 0 #> Columns: 7 #> $ cohort_definition_id #> $ number_records #> $ number_subjects #> $ reason_id #> $ reason #> $ excluded_records #> $ excluded_subjects ``` -------------------------------- ### View Attrition After GI Bleed Cohort Exclusion Source: https://github.com/ohdsi/cohortconstructor/blob/main/README.md Shows the attrition results after applying the requirement that individuals must NOT be in the 'gibleed' cohort within the specified time window. This helps verify the exclusion criteria. ```r attrition(cdm$fractures) |> filter(reason == "Not in cohort gibleed between -Inf & 0 days relative to cohort_start_date") |> glimpse() #> Rows: 0 #> Columns: 7 #> $ cohort_definition_id #> $ number_records #> $ number_subjects #> $ reason_id #> $ reason #> $ excluded_records #> $ excluded_subjects ``` -------------------------------- ### Apply Demographic Requirements to Cohort Source: https://github.com/ohdsi/cohortconstructor/blob/main/README.md Filters the 'fractures' cohort to include only individuals within a specified age range (40-65) and of 'Female' sex. This demonstrates applying demographic filters. ```r cdm$fractures <- cdm$fractures |> requireDemographics(ageRange = list(c(40, 65)), sex = "Female") ``` -------------------------------- ### Disconnect from CDM Source: https://github.com/ohdsi/cohortconstructor/blob/main/README.md Closes the connection to the Common Data Model (CDM). This is a standard practice to release resources after data manipulation is complete. ```r cdmDisconnect(cdm) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.