### Create Cohorts and Get Covariate Data Source: https://ohdsi.github.io/FeatureExtraction/reference/getDbCovariateData.html This example demonstrates setting up connection details using Eunomia, creating cohorts, and then retrieving covariate data using getDbCovariateData. Ensure you have the Eunomia package installed and that the CDM database schema and cohort table are correctly specified. ```r # \donttest{ eunomiaConnectionDetails <- Eunomia::getEunomiaConnectionDetails() covSettings <- createDefaultCovariateSettings() Eunomia::createCohorts( connectionDetails = eunomiaConnectionDetails, cdmDatabaseSchema = "main", cohortDatabaseSchema = "main", cohortTable = "cohort" ) #> Cohorts created in table main.cohort #> cohortId name #> 1 1 Celecoxib #> 2 2 Diclofenac #> 3 3 GiBleed #> 4 4 NSAIDs #> description #> 1 A simplified cohort definition for new users of celecoxib, designed specifically for Eunomia. #> 2 A simplified cohort definition for new users ofdiclofenac, designed specifically for Eunomia. #> 3 A simplified cohort definition for gastrointestinal bleeding, designed specifically for Eunomia. #> 4 A simplified cohort definition for new users of NSAIDs, designed specifically for Eunomia. #> count #> 1 1844 #> 2 850 #> 3 479 #> 4 2694 covData <- getDbCovariateData( connectionDetails = eunomiaConnectionDetails, tempEmulationSchema = NULL, cdmDatabaseSchema = "main", cdmVersion = "5", cohortTable = "cohort", cohortDatabaseSchema = "main", cohortTableIsTemp = FALSE, cohortIds = -1, rowIdField = "subject_id", covariateSettings = covSettings, aggregated = FALSE ) #> Connecting using SQLite driver #> Constructing features on server #> | | | 0% | |= | 1% | |= | 2% | |== | 2% | |== | 3% | |=== | 4% | |=== | 5% | |==== | 5% | |==== | 6% | |===== | 7% | |===== | 8% | |====== # } ``` -------------------------------- ### Create Cohorts and Get Covariate Data Source: https://ohdsi.github.io/FeatureExtraction/reference/getDbCohortAttrCovariatesData.html This example demonstrates setting up a connection, creating cohorts, defining covariate settings, and then extracting covariate data from the database using the getDbCohortAttrCovariatesData function. It requires the Eunomia and DatabaseConnector packages. ```r # \donttest{ connectionDetails <- Eunomia::getEunomiaConnectionDetails() Eunomia::createCohorts( connectionDetails = connectionDetails, cdmDatabaseSchema = "main", cohortDatabaseSchema = "main", cohortTable = "cohort" ) #> Cohorts created in table main.cohort #> cohortId name #> 1 1 Celecoxib #> 2 2 Diclofenac #> 3 3 GiBleed #> 4 4 NSAIDs #> description #> 1 A simplified cohort definition for new users of celecoxib, designed specifically for Eunomia. #> 2 A simplified cohort definition for new users ofdiclofenac, designed specifically for Eunomia. #> 3 A simplified cohort definition for gastrointestinal bleeding, designed specifically for Eunomia. #> 4 A simplified cohort definition for new users of NSAIDs, designed specifically for Eunomia. #> count #> 1 1844 #> 2 850 #> 3 479 #> 4 2694 connection <- DatabaseConnector::connect(connectionDetails) #> Connecting using SQLite driver covariateSettings <- createCohortAttrCovariateSettings( attrDatabaseSchema = "main", cohortAttrTable = "cohort_attribute", attrDefinitionTable = "attribute_definition", includeAttrIds = c(1), isBinary = FALSE, missingMeansZero = FALSE ) covData <- getDbCohortAttrCovariatesData( connection = connection, tempEmulationSchema = NULL, cdmDatabaseSchema = "main", cdmVersion = "5", cohortTable = "cohort", cohortIds = 1, rowIdField = "subject_id", covariateSettings = covariateSettings, aggregated = FALSE ) #> Constructing covariates from cohort attributes table #> Inserting data took 0.0172 secs #> Loading took 0.0838 secs # } ``` -------------------------------- ### R Example: Using createDefaultCovariateSettings Source: https://ohdsi.github.io/FeatureExtraction/reference/createDefaultCovariateSettings.html An example demonstrating how to create covariate settings using createDefaultCovariateSettings with specified concept and covariate IDs. ```r # \donttest{ covSettings <- createDefaultCovariateSettings( includedCovariateConceptIds = c(1), addDescendantsToInclude = FALSE, excludedCovariateConceptIds = c(2), addDescendantsToExclude = FALSE, includedCovariateIds = c(1) ) # } ``` -------------------------------- ### Example: Generating Cohort Data and Table 1 Source: https://ohdsi.github.io/FeatureExtraction/reference/createTable1.html This R code demonstrates a complete workflow: setting up Eunomia connection details, creating default covariate settings, generating cohorts, retrieving covariate data for a specific cohort, and preparing it for table generation. This example is useful for understanding the data preparation steps required before calling `createTable1`. ```r # \donttest{ eunomiaConnectionDetails <- Eunomia::getEunomiaConnectionDetails() covSettings <- createDefaultCovariateSettings() Eunomia::createCohorts( connectionDetails = eunomiaConnectionDetails, cdmDatabaseSchema = "main", cohortDatabaseSchema = "main", cohortTable = "cohort" ) #> Cohorts created in table main.cohort #> cohortId name #> 1 1 Celecoxib #> 2 2 Diclofenac #> 3 3 GiBleed #> 4 4 NSAIDs #> description #> 1 A simplified cohort definition for new users of celecoxib, designed specifically for Eunomia. #> 2 A simplified cohort definition for new users ofdiclofenac, designed specifically for Eunomia. #> 3 A simplified cohort definition for gastrointestinal bleeding, designed specifically for Eunomia. #> 4 A simplified cohort definition for new users of NSAIDs, designed specifically for Eunomia. #> count #> 1 1844 #> 2 850 #> 3 479 #> 4 2694 covData1 <- getDbCovariateData( connectionDetails = eunomiaConnectionDetails, tempEmulationSchema = NULL, cdmDatabaseSchema = "main", cdmVersion = "5", cohortTable = "cohort", cohortDatabaseSchema = "main", cohortTableIsTemp = FALSE, cohortId = 1, rowIdField = "subject_id", covariateSettings = covSettings, aggregated = TRUE ) #> Warning: cohortId argument has been deprecated, please use cohortIds #> Connecting using SQLite driver #> Constructing features on server #> | | | 0% | | | 1% | |= | 1% | |= | 2% | |== | 2% | |== | 3% | |=== | 4% | |=== | 5% | |==== | 5% | |==== | 6% | |===== ``` -------------------------------- ### Create Covariate Settings Example Source: https://ohdsi.github.io/FeatureExtraction/reference/createCovariateSettings.html This example demonstrates how to configure covariate settings using the createCovariateSettings function. It includes various demographic and condition-based covariates, specifying their inclusion and time windows. ```r settings <- createCovariateSettings( useDemographicsGender = TRUE, useDemographicsAge = FALSE, useDemographicsAgeGroup = TRUE, useDemographicsRace = TRUE, useDemographicsEthnicity = TRUE, useDemographicsIndexYear = TRUE, useDemographicsIndexMonth = TRUE, useDemographicsPriorObservationTime = FALSE, useDemographicsPostObservationTime = FALSE, useDemographicsTimeInCohort = FALSE, useDemographicsIndexYearMonth = FALSE, useCareSiteId = FALSE, useConditionOccurrenceAnyTimePrior = FALSE, useConditionOccurrenceLongTerm = FALSE, useConditionOccurrenceMediumTerm = FALSE, useConditionOccurrenceShortTerm = FALSE, useConditionOccurrencePrimaryInpatientAnyTimePrior = FALSE, useConditionOccurrencePrimaryInpatientLongTerm = FALSE, useConditionOccurrencePrimaryInpatientMediumTerm = FALSE, useConditionOccurrencePrimaryInpatientShortTerm = FALSE, useConditionEraAnyTimePrior = FALSE, useConditionEraLongTerm = FALSE, useConditionEraMediumTerm = FALSE, useConditionEraShortTerm = FALSE, useConditionEraOverlapping = FALSE, useConditionEraStartLongTerm = FALSE, useConditionEraStartMediumTerm = FALSE, useConditionEraStartShortTerm = FALSE, useConditionGroupEraAnyTimePrior = FALSE, useConditionGroupEraLongTerm = TRUE, useConditionGroupEraMediumTerm = FALSE, useConditionGroupEraShortTerm = TRUE, useConditionGroupEraOverlapping = FALSE, useConditionGroupEraStartLongTerm = FALSE, useConditionGroupEraStartMediumTerm = FALSE, useConditionGroupEraStartShortTerm = FALSE, useDrugExposureAnyTimePrior = FALSE, useDrugExposureLongTerm = FALSE, useDrugExposureMediumTerm = FALSE, useDrugExposureShortTerm = FALSE, useDrugEraAnyTimePrior = FALSE, useDrugEraLongTerm = FALSE, useDrugEraMediumTerm = FALSE, useDrugEraShortTerm = FALSE, useDrugEraOverlapping = FALSE, useDrugEraStartLongTerm = FALSE, useDrugEraStartMediumTerm = FALSE, useDrugEraStartShortTerm = FALSE, useDrugGroupEraAnyTimePrior = FALSE, useDrugGroupEraLongTerm = TRUE, useDrugGroupEraMediumTerm = FALSE, useDrugGroupEraShortTerm = TRUE, useDrugGroupEraOverlapping = TRUE, useDrugGroupEraStartLongTerm = FALSE, ) ``` -------------------------------- ### Example Usage of createTable1CovariateSettings Source: https://ohdsi.github.io/FeatureExtraction/reference/createTable1CovariateSettings.html Demonstrates how to use the createTable1CovariateSettings function to generate covariate settings for a Table 1. This example shows setting various parameters to their default or empty values. ```r # \donttest{ table1CovSettings <- createTable1CovariateSettings( specifications = getDefaultTable1Specifications(), covariateSettings = createDefaultCovariateSettings(), includedCovariateConceptIds = c(), addDescendantsToInclude = FALSE, excludedCovariateConceptIds = c(), addDescendantsToExclude = FALSE, includedCovariateIds = c() ) # } ``` -------------------------------- ### Example Usage of createDetailedTemporalCovariateSettings Source: https://ohdsi.github.io/FeatureExtraction/reference/createDetailedTemporalCovariateSettings.html This example demonstrates how to use `createDetailedTemporalCovariateSettings` by first creating analysis details and then passing them to the function along with the desired temporal window. ```r # \donttest{ analysisDetails <- createAnalysisDetails( analysisId = 1, sqlFileName = "DemographicsGender.sql", parameters = list( analysisId = 1, analysisName = "Gender", domainId = "Demographics" ), includedCovariateConceptIds = c(), addDescendantsToInclude = FALSE, excludedCovariateConceptIds = c(), addDescendantsToExclude = FALSE, includedCovariateIds = c() ) covSettings <- createDetailedTemporalCovariateSettings( analyses = analysisDetails, temporalStartDays = -365:-1, temporalEndDays = -365:-1 ) # } ``` -------------------------------- ### Example Usage of createAnalysisDetails Source: https://ohdsi.github.io/FeatureExtraction/reference/createAnalysisDetails.html This example demonstrates how to use the createAnalysisDetails function to create settings for a 'Gender' covariate. It specifies the SQL file, parameters, and concept IDs to include or exclude. ```r analysisDetails <- createAnalysisDetails( analysisId = 1, sqlFileName = "DemographicsGender.sql", parameters = list( analysisId = 1, analysisName = "Gender", domainId = "Demographics" ), includedCovariateConceptIds = c(), addDescendantsToInclude = FALSE, excludedCovariateConceptIds = c(), addDescendantsToExclude = FALSE, includedCovariateIds = c() ) ``` -------------------------------- ### Example Usage of getDefaultTable1Specifications Source: https://ohdsi.github.io/FeatureExtraction/reference/getDefaultTable1Specifications.html Demonstrates how to obtain the default table 1 specifications and store them in a variable for later use with the `createTable1` function. ```r # \donttest{ defaultTable1Specs <- getDefaultTable1Specifications() # } ``` -------------------------------- ### Example Covariate Settings Function Source: https://ohdsi.github.io/FeatureExtraction/articles/CreatingCustomCovariateBuilders.html An example of a function that creates a covariateSettings object. This object specifies the parameters for covariate generation and the name of the function that will perform the actual data extraction. ```r createLooCovariateSettings <- function(useLengthOfObs = TRUE) { covariateSettings <- list(useLengthOfObs = useLengthOfObs) attr(covariateSettings, "fun") <- "getDbLooCovariateData" class(covariateSettings) <- "covariateSettings" return(covariateSettings) } ``` -------------------------------- ### Example Usage of computeStandardizedDifference Source: https://ohdsi.github.io/FeatureExtraction/reference/computeStandardizedDifference.html This example demonstrates how to load covariate data and then compute the standardized difference between two cohorts using `computeStandardizedDifference`. Ensure covariate data is loaded before calling the function. ```R # \donttest{ binaryCovDataFile <- system.file("testdata/binaryCovariateData.zip", package = "FeatureExtraction" ) covariateData1 <- loadCovariateData(binaryCovDataFile) covariateData2 <- loadCovariateData(binaryCovDataFile) covDataDiff <- computeStandardizedDifference( covariateData1, covariateData2, cohortId1 = 1, cohortId2 = 2 ) # } ``` -------------------------------- ### Install FeatureExtraction Package Source: https://ohdsi.github.io/FeatureExtraction/index.html Install the FeatureExtraction package and its dependencies from the OHDSI repository. Ensure you have RTools and Java installed. ```r install.packages("drat") drat::addRepo("OHDSI") install.packages("FeatureExtraction") ``` -------------------------------- ### Database Connection Details (PostgreSQL) Source: https://ohdsi.github.io/FeatureExtraction/articles/UsingFeatureExtraction.html Configures connection details for a PostgreSQL database. This setup is required for the CohortMethod package to access the data. ```R connectionDetails <- createConnectionDetails( dbms = "postgresql", server = "localhost/ohdsi", user = "joe", password = "supersecret" ) ``` -------------------------------- ### Create Default Covariate Settings Source: https://ohdsi.github.io/FeatureExtraction/articles/UsingFeatureExtraction.html Generates a comprehensive set of default covariates. This is the simplest way to start. ```r settings <- createDefaultCovariateSettings() ``` -------------------------------- ### R Example for createCohortAttrCovariateSettings Source: https://ohdsi.github.io/FeatureExtraction/reference/createCohortAttrCovariateSettings.html Demonstrates how to use createCohortAttrCovariateSettings to define covariate settings based on cohort attributes. Ensure the specified database schema and tables exist. ```r # \donttest{ covariateSettings <- createCohortAttrCovariateSettings( analysisId = 1, attrDatabaseSchema = "main", attrDefinitionTable = "attribute_definition", cohortAttrTable = "cohort_attribute", includeAttrIds = c(1), isBinary = FALSE, missingMeansZero = FALSE ) # } ``` -------------------------------- ### Example Usage of createDetailedCovariateSettings Source: https://ohdsi.github.io/FeatureExtraction/reference/createDetailedCovariateSettings.html Demonstrates how to create analysis details and then use them to generate detailed covariate settings. This is intended for advanced users. ```r # \donttest{ analysisDetails <- createAnalysisDetails( analysisId = 1, sqlFileName = "DemographicsGender.sql", parameters = list( analysisId = 1, analysisName = "Gender", domainId = "Demographics" ), includedCovariateConceptIds = c(), addDescendantsToInclude = FALSE, excludedCovariateConceptIds = c(), addDescendantsToExclude = FALSE, includedCovariateIds = c() ) covSettings <- createDetailedCovariateSettings(analyses = analysisDetails) # } ``` -------------------------------- ### R Example: Creating Covariate Settings Source: https://ohdsi.github.io/FeatureExtraction/reference/createDefaultTemporalCovariateSettings.html Demonstrates how to use createDefaultTemporalCovariateSettings to define covariate settings, specifying included and excluded concept IDs and covariate IDs. ```r # \donttest{ covSettings <- createDefaultTemporalCovariateSettings( includedCovariateConceptIds = c(1), addDescendantsToInclude = FALSE, excludedCovariateConceptIds = c(2), addDescendantsToExclude = FALSE, includedCovariateIds = c(1) ) # } ``` -------------------------------- ### Example Usage of tidyCovariateData Source: https://ohdsi.github.io/FeatureExtraction/reference/tidyCovariateData.html Demonstrates how to use the tidyCovariateData function to clean and normalize covariate data. Requires creating an empty covariate data object first. ```r # \donttest{ covariateData <- FeatureExtraction::createEmptyCovariateData( cohortIds = 1, aggregated = FALSE, temporal = FALSE ) covData <- tidyCovariateData( covariateData = covariateData, minFraction = 0.001, normalize = TRUE, removeRedundancy = TRUE ) #> Tidying covariates took 1.71 secs # } ``` -------------------------------- ### Default Temporal Covariate Settings Source: https://ohdsi.github.io/FeatureExtraction/articles/UsingFeatureExtraction.html Creates default settings for temporal covariates. This is a convenient way to start when using temporal covariates. ```R settings <- createDefaultTemporalCovariateSettings() ``` -------------------------------- ### Create Temporal Sequence Covariate Settings Source: https://ohdsi.github.io/FeatureExtraction/reference/createTemporalSequenceCovariateSettings.html Generates covariate settings for temporal sequence analysis. This example includes demographic features, procedure, device, measurement, and observation data, with a time window of -730 to -1 days relative to the index date. ```R settings <- createTemporalSequenceCovariateSettings( useDemographicsGender = TRUE, useDemographicsAge = FALSE, useDemographicsAgeGroup = TRUE, useDemographicsRace = TRUE, useDemographicsEthnicity = TRUE, useDemographicsIndexYear = TRUE, useDemographicsIndexMonth = TRUE, useConditionOccurrence = FALSE, useConditionOccurrencePrimaryInpatient = FALSE, useConditionEraStart = FALSE, useConditionEraGroupStart = FALSE, useDrugExposure = FALSE, useDrugEraStart = FALSE, useDrugEraGroupStart = FALSE, useProcedureOccurrence = TRUE, useDeviceExposure = TRUE, useMeasurement = TRUE, useMeasurementValue = FALSE, useObservation = TRUE, timePart = "DAY", timeInterval = 1, sequenceEndDay = -1, sequenceStartDay = -730, includedCovariateConceptIds = c(), addDescendantsToInclude = FALSE, excludedCovariateConceptIds = c(), addDescendantsToExclude = FALSE, includedCovariateIds = c() ) ``` -------------------------------- ### Load Covariate Data from File Source: https://ohdsi.github.io/FeatureExtraction/reference/loadCovariateData.html Loads an object of class CovariateData from a zip file. Ensure the FeatureExtraction package is installed and loaded. ```r binaryCovDataFile <- system.file("testdata/binaryCovariateData.zip", package = "FeatureExtraction" ) covData <- loadCovariateData(binaryCovDataFile) ``` -------------------------------- ### SQL for Creating Cohort Attributes and Definitions Source: https://ohdsi.github.io/FeatureExtraction/articles/CreatingCovariatesUsingCohortAttributes.html This SQL script creates a cohort attribute table and an attribute definition table. It calculates the length of observation prior to the cohort start date. ```sql ----------------------------------- File LengthOfObsCohortAttr.sql ----------------------------------- IF OBJECT_ID('@cohort_database_schema.@cohort_attribute_table', 'U') IS NOT NULL DROP TABLE @cohort_database_schema.@cohort_attribute_table; IF OBJECT_ID('@cohort_database_schema.@attribute_definition_table', 'U') IS NOT NULL DROP TABLE @cohort_database_schema.@attribute_definition_table; SELECT cohort_definition_id, subject_id, cohort_start_date, 1 AS attribute_definition_id, DATEDIFF(DAY, observation_period_start_date, cohort_start_date) AS value_as_number INTO @cohort_database_schema.@cohort_attribute_table FROM @cohort_database_schema.@cohort_table cohort INNER JOIN @cdm_database_schema.observation_period op ON op.person_id = cohort.subject_id WHERE cohort_start_date >= observation_period_start_date AND cohort_start_date <= observation_period_end_date {@cohort_definition_ids != ''} ? { AND cohort_definition_id IN (@cohort_definition_ids) } ; SELECT 1 AS attribute_definition_id, 'Length of observation in days' AS attribute_name INTO @cohort_database_schema.@attribute_definition_table; ``` -------------------------------- ### Create Cohorts of Interest SQL Source: https://ohdsi.github.io/FeatureExtraction/articles/UsingFeatureExtraction.html SQL script to create a table of cohorts of interest based on drug eras and observation periods. It requires 365 days of observation prior to the cohort start date. ```sql /*********************************** File cohortsOfInterest.sql **********************************/ IF OBJECT_ID('@resultsDatabaseSchema.cohorts_of_interest', 'U') IS NOT NULL DROP TABLE @resultsDatabaseSchema.cohorts_of_interest; SELECT first_use.* INTO @resultsDatabaseSchema.cohorts_of_interest FROM ( SELECT drug_concept_id AS cohort_definition_id, MIN(drug_era_start_date) AS cohort_start_date, MIN(drug_era_end_date) AS cohort_end_date, person_id FROM @cdmDatabaseSchema.drug_era WHERE drug_concept_id = 1118084-- celecoxib OR drug_concept_id = 1124300 --diclofenac GROUP BY drug_concept_id, person_id ) first_use INNER JOIN @cdmDatabaseSchema.observation_period ON first_use.person_id = observation_period.person_id AND cohort_start_date >= observation_period_start_date AND cohort_end_date <= observation_period_end_date WHERE DATEDIFF(DAY, observation_period_start_date, cohort_start_date) >= 365; ``` -------------------------------- ### Default Covariate Settings Source: https://ohdsi.github.io/FeatureExtraction/reference/createCovariateSettings.html This snippet shows the default settings for creating covariates. It includes configurations for drug eras, procedure occurrences, device exposures, measurements, observations, and various comorbidity indices. Use this as a starting point for defining your covariate generation strategy. ```R createCovariateSettings( useDrugGroupEraStartMediumTerm = FALSE, useDrugGroupEraStartShortTerm = FALSE, useProcedureOccurrenceAnyTimePrior = FALSE, useProcedureOccurrenceLongTerm = TRUE, useProcedureOccurrenceMediumTerm = FALSE, useProcedureOccurrenceShortTerm = TRUE, useDeviceExposureAnyTimePrior = FALSE, useDeviceExposureLongTerm = TRUE, useDeviceExposureMediumTerm = FALSE, useDeviceExposureShortTerm = TRUE, useMeasurementAnyTimePrior = FALSE, useMeasurementLongTerm = TRUE, useMeasurementMediumTerm = FALSE, useMeasurementShortTerm = TRUE, useMeasurementValueAnyTimePrior = FALSE, useMeasurementValueLongTerm = FALSE, useMeasurementValueMediumTerm = FALSE, useMeasurementValueShortTerm = FALSE, useMeasurementRangeGroupAnyTimePrior = FALSE, useMeasurementRangeGroupLongTerm = TRUE, useMeasurementRangeGroupMediumTerm = FALSE, useMeasurementRangeGroupShortTerm = TRUE, useMeasurementValueAsConceptAnyTimePrior = FALSE, useMeasurementValueAsConceptLongTerm = TRUE, useMeasurementValueAsConceptMediumTerm = FALSE, useMeasurementValueAsConceptShortTerm = TRUE, useObservationAnyTimePrior = FALSE, useObservationLongTerm = TRUE, useObservationMediumTerm = FALSE, useObservationShortTerm = TRUE, useObservationValueAsConceptAnyTimePrior = FALSE, useObservationValueAsConceptLongTerm = TRUE, useObservationValueAsConceptMediumTerm = FALSE, useObservationValueAsConceptShortTerm = TRUE, useCharlsonIndex = TRUE, useDcsi = TRUE, useChads2 = TRUE, useChads2Vasc = TRUE, useHfrs = FALSE, useDistinctConditionCountLongTerm = FALSE, useDistinctConditionCountMediumTerm = FALSE, useDistinctConditionCountShortTerm = FALSE, useDistinctIngredientCountLongTerm = FALSE, useDistinctIngredientCountMediumTerm = FALSE, useDistinctIngredientCountShortTerm = FALSE, useDistinctProcedureCountLongTerm = FALSE, useDistinctProcedureCountMediumTerm = FALSE, useDistinctProcedureCountShortTerm = FALSE, useDistinctMeasurementCountLongTerm = FALSE, useDistinctMeasurementCountMediumTerm = FALSE, useDistinctMeasurementCountShortTerm = FALSE, useDistinctObservationCountLongTerm = FALSE, useDistinctObservationCountMediumTerm = FALSE, useDistinctObservationCountShortTerm = FALSE, useVisitCountLongTerm = FALSE, useVisitCountMediumTerm = FALSE, useVisitCountShortTerm = FALSE, useVisitConceptCountLongTerm = FALSE, useVisitConceptCountMediumTerm = FALSE, useVisitConceptCountShortTerm = FALSE, longTermStartDays = -365, mediumTermStartDays = -180, shortTermStartDays = -30, endDays = 0, includedCovariateConceptIds = c(), addDescendantsToInclude = FALSE, excludedCovariateConceptIds = c(), addDescendantsToExclude = FALSE, includedCovariateIds = c() ) ``` -------------------------------- ### Setting up Eunomia and Creating Cohorts Source: https://ohdsi.github.io/FeatureExtraction/reference/getDbDefaultCovariateData.html This snippet demonstrates how to establish a connection to the Eunomia database and create cohort tables. It is a prerequisite for running covariate extraction functions. ```r # \donttest{ connectionDetails <- Eunomia::getEunomiaConnectionDetails() Eunomia::createCohorts( connectionDetails = connectionDetails, cdmDatabaseSchema = "main", cohortDatabaseSchema = "main", cohortTable = "cohort" ) #> Cohorts created in table main.cohort #> cohortId name #> 1 1 Celecoxib #> 2 2 Diclofenac #> 3 3 GiBleed #> 4 4 NSAIDs #> description #> 1 A simplified cohort definition for new users of celecoxib, designed specifically for Eunomia. #> 2 A simplified cohort definition for new users ofdiclofenac, designed specifically for Eunomia. #> 3 A simplified cohort definition for gastrointestinal bleeding, designed specifically for Eunomia. #> 4 A simplified cohort definition for new users of NSAIDs, designed specifically for Eunomia. #> count #> 1 1844 #> 2 850 #> 3 479 #> 4 2694 ``` -------------------------------- ### Executing SQL and Fetching Data Source: https://ohdsi.github.io/FeatureExtraction/reference/getDbCovariateData.html Shows the process of executing SQL queries and fetching data from the server, along with the time taken for each step. ```text #> Executing SQL took 2.06 secs #> Fetching data from server #> Fetching data took 0.671 secs # } ``` -------------------------------- ### Get Deleted Redundant Covariate IDs Source: https://ohdsi.github.io/FeatureExtraction/articles/UsingFeatureExtraction.html Retrieves the IDs of covariates that were removed because they were redundant. ```r deletedCovariateIds <- attr(tidyCovariates, "metaData")$deletedRedundantCovariateIds ``` -------------------------------- ### getDbCovariateData Source: https://ohdsi.github.io/FeatureExtraction/reference/index.html Get covariate information from the database. This is a general function to retrieve covariate data from the database. ```APIDOC ## getDbCovariateData ### Description Get covariate information from the database. ### Method Not applicable (function call) ### Endpoint Not applicable (function call) ### Parameters None explicitly documented. ### Request Example ``` getDbCovariateData() ``` ### Response Not explicitly documented. Likely returns covariate data from the database. ``` -------------------------------- ### Database Query Execution and Data Fetching Source: https://ohdsi.github.io/FeatureExtraction/reference/getDbDefaultCovariateData.html Shows the process of executing a SQL query against a database and fetching the resulting data. Includes timing information for query execution and data retrieval. ```r #> Executing SQL took 2.06 secs #> Fetching data from server #> Fetching data took 0.635 secs # } ``` -------------------------------- ### getDbDefaultCovariateData Source: https://ohdsi.github.io/FeatureExtraction/reference/index.html Get default covariate information from the database. This function retrieves default covariate data stored in the database. ```APIDOC ## getDbDefaultCovariateData ### Description Get default covariate information from the database. ### Method Not applicable (function call) ### Endpoint Not applicable (function call) ### Parameters None explicitly documented. ### Request Example ``` getDbDefaultCovariateData() ``` ### Response Not explicitly documented. Likely returns default covariate data from the database. ``` -------------------------------- ### Get Default Table 1 Specifications Source: https://ohdsi.github.io/FeatureExtraction/reference/getDefaultTable1Specifications.html Call this function to retrieve the default specifications object for table 1 creation. ```r getDefaultTable1Specifications() ``` -------------------------------- ### Execute Parameterized SQL with SqlRender Source: https://ohdsi.github.io/FeatureExtraction/articles/UsingFeatureExtraction.html R code to read, render, translate, and execute parameterized SQL. This allows for schema and dialect flexibility. ```r library(SqlRender) sql <- readSql("cohortsOfInterest.sql") sql <- render(sql, cdmDatabaseSchema = cdmDatabaseSchema, resultsDatabaseSchema = resultsDatabaseSchema ) sql <- translate(sql, targetDialect = connectionDetails$dbms) connection <- connect(connectionDetails) executeSql(connection, sql) ``` -------------------------------- ### getDbCohortAttrCovariatesData Source: https://ohdsi.github.io/FeatureExtraction/reference/index.html Get covariate information from the database through the cohort_attribute table. This function retrieves specific covariate data related to cohort attributes. ```APIDOC ## getDbCohortAttrCovariatesData ### Description Get covariate information from the database through the cohort_attribute table. ### Method Not applicable (function call) ### Endpoint Not applicable (function call) ### Parameters None explicitly documented. ### Request Example ``` getDbCohortAttrCovariatesData() ``` ### Response Not explicitly documented. Likely returns covariate data from the cohort_attribute table. ``` -------------------------------- ### Get Deleted Infrequent Covariate IDs Source: https://ohdsi.github.io/FeatureExtraction/articles/UsingFeatureExtraction.html Retrieves the IDs of covariates that were removed due to being infrequent (appearing in less than minFraction of subjects). ```r deletedCovariateIds <- attr(tidyCovariates, "metaData")$deletedInfrequentCovariateIds ``` -------------------------------- ### Generate Table 1 with Custom Specifications Source: https://ohdsi.github.io/FeatureExtraction/reference/createTable1.html Use this snippet to create a Table 1 by providing two covariate datasets, cohort IDs, and custom specifications. It demonstrates how to control output formatting like counts, percentages, and decimal places. ```r table1 <- createTable1( covariateData1 = covData1, covariateData2 = covData2, cohortId1 = 1, cohortId2 = 2, specifications = getDefaultTable1Specifications(), output = "one column", showCounts = FALSE, showPercent = TRUE, percentDigits = 1, valueDigits = 1, stdDiffDigits = 2 ) ``` -------------------------------- ### Create Default Covariate Settings Source: https://ohdsi.github.io/FeatureExtraction/articles/UsingFeatureExtraction.html Generates default settings for creating covariates. This is the first step before fetching covariate data. ```r covariateSettings <- createDefaultCovariateSettings() ``` -------------------------------- ### Execute SQL with R Source: https://ohdsi.github.io/FeatureExtraction/articles/CreatingCovariatesBasedOnOtherCohorts.html This R code reads an SQL file, connects to the database, and executes the SQL script using SqlRender for translation and execution. ```r library(SqlRender) sql <- readSql("covariateCohorts.sql") connection <- connect(connectionDetails) renderTranslateExecuteSql( connection = connection, sql = sql, cdm_database_schema = cdmDatabaseSchema, cohort_database_schema = cohortDatabaseSchema, cohort_table = cohortTable ) ``` -------------------------------- ### Create Detailed Covariate Settings Source: https://ohdsi.github.io/FeatureExtraction/reference/createDetailedCovariateSettings.html Basic function signature for creating detailed covariate settings. ```r createDetailedCovariateSettings(analyses = list()) ``` -------------------------------- ### Get Covariate Data for Table 1 Source: https://ohdsi.github.io/FeatureExtraction/reference/createTable1.html Retrieves covariate data from the database to be used for generating Table 1. Ensure connection details and cohort settings are properly configured. ```r covData2 <- getDbCovariateData( connectionDetails = eunomiaConnectionDetails, tempEmulationSchema = NULL, cdmDatabaseSchema = "main", cdmVersion = "5", cohortTable = "cohort", cohortDatabaseSchema = "main", cohortTableIsTemp = FALSE, cohortId = 2, rowIdField = "subject_id", covariateSettings = covSettings, aggregated = TRUE ) ``` -------------------------------- ### Define and Populate Cohort Tables Source: https://ohdsi.github.io/FeatureExtraction/articles/CreatingCovariatesBasedOnOtherCohorts.html This SQL script defines two cohorts: one for diclofenac initiation and another for type 2 diabetes. It creates and inserts data into a specified cohort table. ```sql /************************ File covariateCohorts.sql *************************/ DROP TABLE IF EXISTS @cohort_database_schema.@cohort_table; CREATE TABLE @cohort_database_schema.@cohort_table ( cohort_definition_id INT, subject_id BIGINT, cohort_start_date DATE, cohort_end_date DATE ); INSERT INTO @cohort_database_schema.@cohort_table ( cohort_definition_id, subject_id, cohort_start_date, cohort_end_date ) SELECT 1, person_id, MIN(drug_era_start_date), MIN(drug_era_end_date) FROM @cdm_database_schema.drug_era WHERE drug_concept_id = 1124300 --diclofenac GROUP BY person_id; INSERT INTO @cohort_database_schema.@cohort_table ( cohort_definition_id, subject_id, cohort_start_date, cohort_end_date ) SELECT 2, condition_occurrence.person_id, MIN(condition_start_date), MIN(observation_period_end_date) FROM @cdm_database_schema.condition_occurrence INNER JOIN @cdm_database_schema.drug_exposure ON condition_occurrence.person_id = drug_exposure.person_id AND drug_exposure_start_date >= condition_start_date AND drug_exposure_start_date < DATEADD(DAY, 30, condition_start_date) INNER JOIN @cdm_database_schema.observation_period ON condition_occurrence.person_id = observation_period.person_id AND condition_start_date >= observation_period_start_date AND condition_start_date <= observation_period_end_date WHERE condition_concept_id IN ( SELECT descendant_concept_id FROM @cdm_database_schema.concept_ancestor WHERE ancestor_concept_id = 201826 -- Type 2 diabetes mellitus ) AND drug_concept_id IN ( SELECT descendant_concept_id FROM @cdm_database_schema.concept_ancestor WHERE ancestor_concept_id = 21600712 -- DRUGS USED IN DIABETES (ATC A10) ) GROUP BY condition_occurrence.person_id; ``` -------------------------------- ### Get Covariate Data for Cohort Source: https://ohdsi.github.io/FeatureExtraction/articles/UsingFeatureExtraction.html Extract covariate data from the CDM database for a specified cohort and covariate settings. Ensure connection details, schemas, and cohort information are correctly provided. ```r covCelecoxib <- getDbCovariateData( connectionDetails = connectionDetails, cdmDatabaseSchema = cdmDatabaseSchema, cohortDatabaseSchema = resultsDatabaseSchema, cohortTable = "cohorts_of_interest", cohortIds = c(1118084), covariateSettings = settings, aggregated = TRUE ) ``` ```r covDiclofenac <- getDbCovariateData( connectionDetails = connectionDetails, cdmDatabaseSchema = cdmDatabaseSchema, cohortDatabaseSchema = resultsDatabaseSchema, cohortTable = "cohorts_of_interest", cohortIds = c(1118084), covariateSettings = settings, aggregated = TRUE ) ``` -------------------------------- ### Rendering and Executing SQL with SqlRender Source: https://ohdsi.github.io/FeatureExtraction/articles/CreatingCovariatesUsingCohortAttributes.html This R code uses SqlRender to read, render, and translate SQL, then executes it against a database connection. Ensure connection details and schemas are correctly configured. ```r library(SqlRender) sql <- readSql("LengthOfObsCohortAttr.sql") sql <- render(sql, cdm_database_schema = cdmDatabaseSchema, cohort_database_schema = cohortDatabaseSchema, cohort_table = "rehospitalization", cohort_attribute_table = "loo_cohort_attr", attribute_definition_table = "loo_attr_def", cohort_definition_ids = c(1, 2) ) sql <- translate(sql, targetDialect = connectionDetails$dbms) connection <- connect(connectionDetails) executeSql(connection, sql) ``` -------------------------------- ### getDefaultTable1Specifications Source: https://ohdsi.github.io/FeatureExtraction/reference/getDefaultTable1Specifications.html Loads the default specifications for a table 1, to be used with the createTable1 function. ```APIDOC ## getDefaultTable1Specifications ### Description Loads the default specifications for a table 1, to be used with the `createTable1` function. ### Method ```R getDefaultTable1Specifications() ``` ### Returns A specifications object. ``` -------------------------------- ### Prespecified Temporal Covariate Settings Source: https://ohdsi.github.io/FeatureExtraction/articles/UsingFeatureExtraction.html Creates temporal covariate settings using prespecified options for condition occurrence and measurement values. By default, covariates are created daily for the 365 days prior to cohort start. ```R settings <- createTemporalCovariateSettings( useConditionOccurrence = TRUE, useMeasurementValue = TRUE ) ``` -------------------------------- ### Get Per-Person Covariate Data Source: https://ohdsi.github.io/FeatureExtraction/articles/UsingFeatureExtraction.html Fetches per-person covariate data for a specified cohort. Requires connection details, CDM schema, cohort schema, cohort table, cohort IDs, row ID field, and covariate settings. ```r covariateData <- getDbCovariateData( connectionDetails = connectionDetails, cdmDatabaseSchema = cdmDatabaseSchema, cohortDatabaseSchema = resultsDatabaseSchema, cohortTable = "cohorts_of_interest", cohortIds = c(1118084), rowIdField = "subject_id", covariateSettings = covariateSettings ) ``` -------------------------------- ### createAnalysisDetails Source: https://ohdsi.github.io/FeatureExtraction/reference/index.html Create detailed covariate settings. This function is used to define detailed settings for creating covariates. ```APIDOC ## createAnalysisDetails ### Description Create detailed covariate settings. ### Method Not applicable (function call) ### Endpoint Not applicable (function call) ### Parameters None explicitly documented. ### Request Example ``` createAnalysisDetails() ``` ### Response Not explicitly documented. Likely returns detailed covariate settings. ``` -------------------------------- ### Create Temporal Covariate Settings Source: https://ohdsi.github.io/FeatureExtraction/reference/createTemporalCovariateSettings.html This snippet demonstrates how to configure various demographic and clinical event covariates for temporal analysis. It specifies which types of data to include and defines the temporal windows for covariate generation. ```r settings <- createTemporalCovariateSettings( useDemographicsGender = TRUE, useDemographicsAge = FALSE, useDemographicsAgeGroup = TRUE, useDemographicsRace = TRUE, useDemographicsEthnicity = TRUE, useDemographicsIndexYear = TRUE, useDemographicsIndexMonth = TRUE, useDemographicsPriorObservationTime = FALSE, useDemographicsPostObservationTime = FALSE, useDemographicsTimeInCohort = FALSE, useDemographicsIndexYearMonth = FALSE, useCareSiteId = FALSE, useConditionOccurrence = FALSE, useConditionOccurrencePrimaryInpatient = FALSE, useConditionEraStart = FALSE, useConditionEraOverlap = FALSE, useConditionEraGroupStart = FALSE, useConditionEraGroupOverlap = TRUE, useDrugExposure = FALSE, useDrugEraStart = FALSE, useDrugEraOverlap = FALSE, useDrugEraGroupStart = FALSE, useDrugEraGroupOverlap = TRUE, useProcedureOccurrence = TRUE, useDeviceExposure = TRUE, useMeasurement = TRUE, useMeasurementValue = FALSE, useMeasurementRangeGroup = TRUE, useMeasurementValueAsConcept = TRUE, useObservation = TRUE, useObservationValueAsConcept = TRUE, useCharlsonIndex = TRUE, useDcsi = TRUE, useChads2 = TRUE, useChads2Vasc = TRUE, useHfrs = FALSE, useDistinctConditionCount = FALSE, useDistinctIngredientCount = FALSE, useDistinctProcedureCount = FALSE, useDistinctMeasurementCount = FALSE, useDistinctObservationCount = FALSE, useVisitCount = FALSE, useVisitConceptCount = FALSE, temporalStartDays = -365:-1, temporalEndDays = -365:-1, includedCovariateConceptIds = c(), addDescendantsToInclude = FALSE, excludedCovariateConceptIds = c(), addDescendantsToExclude = FALSE, includedCovariateIds = c() ) ``` -------------------------------- ### Custom Temporal Covariate Settings with Intervals Source: https://ohdsi.github.io/FeatureExtraction/articles/UsingFeatureExtraction.html Creates temporal covariate settings with custom time windows defined as 7-day intervals. This allows for a more granular temporal resolution. ```R settings <- createTemporalCovariateSettings( useConditionOccurrence = TRUE, useMeasurementValue = TRUE, temporalStartDays = seq(-364, -7, by = 7), temporalEndDays = seq(-358, -1, by = 7) ) ``` -------------------------------- ### Create Table 1 Comparison Source: https://ohdsi.github.io/FeatureExtraction/articles/UsingFeatureExtraction.html Generate a standard Table 1 comparison between two sets of covariate data, outputting results in two columns for easy side-by-side viewing. ```r result <- createTable1( covariateData1 = covCelecoxib, covariateData2 = covDiclofenac, output = "two columns" ) print(result, row.names = FALSE, right = FALSE) ```