Skip to content

Commit

Permalink
some vignette tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
edward-burn committed Oct 23, 2024
1 parent 0ce46f5 commit 9e42a9d
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 158 deletions.
61 changes: 23 additions & 38 deletions vignettes/a01_building_base_cohorts.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -41,56 +41,41 @@ cdm <- cdm_from_con(con, cdm_schema = "main",
write_schema = c(prefix = "my_study_", schema = "main"))
```

## Demographic based cohort creation
## Concept based cohort creation

One base cohort we can create is based around patient demographics. Here for example we create a cohort where people enter on their 18th birthday and leave at age 65 or
A way of defining base cohorts is to identify clinical records with codes from some pre-specified list. Here for example we'll first find codes for diclofenac and acetaminophen.

```{r}
cdm$working_age_cohort <- demographicsCohort(cdm = cdm,
ageRange = c(18, 65),
name = "working_age_cohort")
drug_codes <- getDrugIngredientCodes(cdm,
name = c("acetaminophen",
"amoxicillin",
"diclofenac",
"simvastatin",
"warfarin"))
settings(cdm$working_age_cohort)
cohortCount(cdm$working_age_cohort)
attrition(cdm$working_age_cohort)
drug_codes
```

Now we have our codes of interest, we'll make cohorts for each of these where cohort exit is defined as the event start date (which for these will be their drug exposure end date).

```{r}
cdm$working_age_cohort |>
addAge(indexDate = "cohort_start_date") |>
summarise(min_start_age = min(age),
median_start_age = median(age),
max_start_age = max(age))
cdm$working_age_cohort |>
addAge(indexDate = "cohort_end_date") |>
summarise(min_start_age = min(age),
median_start_age = median(age),
max_start_age = max(age))
cdm$drugs <- conceptCohort(cdm,
conceptSet = drug_codes,
exit = "event_end_date",
name = "drugs")
settings(cdm$drugs)
cohortCount(cdm$drugs)
attrition(cdm$drugs)
```

## Concept based cohort creation

```{r}
drug_codes <- getDrugIngredientCodes(cdm,
name = c("diclofenac",
"acetaminophen"))
## Demographic based cohort creation

drug_codes
```
One base cohort we can create is based around patient demographics. Here for example we create a cohort where people enter on their 18th birthday and leave at on the day before their 66th birthday.

```{r}
cdm$medications <- conceptCohort(cdm = cdm,
conceptSet = drug_codes,
name = "medications")
settings(cdm$medications)
cohortCount(cdm$medications)
cdm$working_age_cohort <- demographicsCohort(cdm = cdm,
ageRange = c(18, 65),
name = "working_age_cohort")
```

## Concept based cohort creation for measurements

TO DO


157 changes: 37 additions & 120 deletions vignettes/a04_require_intersections.Rmd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: "Requirements on Presence and Absence"
title: "Requirements related to other cohorts, concept sets, or tables"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{a04_require_intersections}
Expand All @@ -14,8 +14,10 @@ knitr::opts_chunk$set(
```

```{r setup}
library(CodelistGenerator)
library(CohortConstructor)
library(CohortCharacteristics)
library(visOmopResults)
library(ggplot2)
```

Expand Down Expand Up @@ -44,185 +46,100 @@ cdm <- cdm_from_con(con, cdm_schema = "main",
write_schema = c(prefix = "my_study_", schema = "main"))
```

Let's start by creating two drug cohorts, one for users of diclofenac and another for users of acetaminophen.
Let's start by creating a cohort of warfarin users.

```{r}
cdm$medications <- conceptCohort(cdm = cdm,
conceptSet = list("diclofenac" = 1124300,
"acetaminophen" = 1127433),
name = "medications")
cohortCount(cdm$medications)
warfarin_codes <- getDrugIngredientCodes(cdm, "warfarin")
cdm$warfarin <- conceptCohort(cdm = cdm,
conceptSet = warfarin_codes,
name = "warfarin")
cohortCount(cdm$warfarin)
```

As well as our medication cohorts, let's also make another cohort containing individuals with a record of a GI bleed. Later we'll use this cohort when specifying inclusion/ exclusion criteria.
As well as our warfarin cohort, let's also make another cohort containing individuals with a record of a GI bleed. Later we'll use this cohort when specifying inclusion/ exclusion criteria.

```{r}
cdm$gi_bleed <- conceptCohort(cdm = cdm,
conceptSet = list("gi_bleed" = 192671),
conceptSet = list("gi_bleed" = 192671L),
name = "gi_bleed")
```

## Restrictions on cohort presence

We could require that individuals in our medication cohorts are seen (or not seen) in another cohort. To do this we can use the `requireCohortIntersect()` function, requiring that individuals have one or more intersections with the GI bleed cohort.
We could require that individuals in our medication cohorts are seen (or not seen) in another cohort. To do this we can use the `requireCohortIntersect()` function. Here, for example, we require that individuals have one or more intersections with the GI bleed cohort.

```{r}
cdm$medications_gi_bleed <- cdm$medications %>%
cdm$warfarin_gi_bleed <- cdm$warfarin %>%
requireCohortIntersect(intersections = c(1,Inf),
targetCohortTable = "gi_bleed",
targetCohortId = 1,
indexDate = "cohort_start_date",
window = c(-Inf, 0),
name = "medications_gi_bleed")
name = "warfarin_gi_bleed")
summary_attrition <- summariseCohortAttrition(cdm$medications_gi_bleed)
plotCohortAttrition(summary_attrition, cohortId = 1)
summary_attrition <- summariseCohortAttrition(cdm$warfarin_gi_bleed)
plotCohortAttrition(summary_attrition)
```

The flow chart above illustrates the changes to cohort 1 (users of acetaminophen) when restricted to only include individuals who intersect with the GI bleed cohort at least once before the cohort start date. 2,296 individuals and 8,765 records were excluded.
The flow chart above illustrates the changes to the cohort of users of acetaminophen when restricted to only include individuals who have at least one record in the GI bleed cohort before their start date for acetaminophen.

Instead of requiring that individuals intersect with the GI bleed cohort, we could instead require that they don't intersect with it. In this case we can again use the `requireCohortIntersect()` function, but this time set the intersections argument to 0 to require individuals' absence in this other cohort rather than their presence in it.
Instead of requiring that individuals have a record in the GI bleed cohort, we could instead require that they don't. In this case we can again use the `requireCohortIntersect()` function, but this time we set the intersections argument to 0 so as to require individuals' absence in this other cohort.

```{r}
cdm$medications_no_gi_bleed <- cdm$medications %>%
cdm$warfarin_no_gi_bleed <- cdm$warfarin %>%
requireCohortIntersect(intersections = 0,
targetCohortTable = "gi_bleed",
targetCohortId = 1,
indexDate = "cohort_start_date",
window = c(-Inf, 0),
name = "medications_no_gi_bleed")
name = "warfarin_no_gi_bleed")
summary_attrition <- summariseCohortAttrition(cdm$medications_no_gi_bleed)
plotCohortAttrition(summary_attrition, cohortId = 1)
summary_attrition <- summariseCohortAttrition(cdm$warfarin_no_gi_bleed)
plotCohortAttrition(summary_attrition)
```

The flow chart above illustrates the changes to cohort 1 when restricted to only include individuals with no intersects with the GI bleed cohort before the cohort start date. 36 individuals and 600 records were excluded.


## Restrictions on concept presence

We could require that individuals in our medication cohorts have been seen (or not seen) to have events related to a concept list. To do this we can use the `requireConceptIntersect()` function, allowing us to filter our cohort based on whether they have or have not had events of GI bleeding before they entered the cohort.

```{r, include = FALSE}
cdm$medications <- conceptCohort(cdm = cdm,
conceptSet = list("diclofenac" = 1124300,
"acetaminophen" = 1127433),
name = "medications")
cdm$gi_bleed <- conceptCohort(cdm = cdm,
conceptSet = list("gi_bleed" = 192671),
name = "gi_bleed")
```

```{r}
cdm$medications_gi_bleed <- cdm$medications %>%
cdm$warfarin_gi_bleed <- cdm$warfarin %>%
requireConceptIntersect(conceptSet = list("gi_bleed" = 192671),
indexDate = "cohort_start_date",
window = c(-Inf, 0),
name = "medications_gi_bleed")
name = "warfarin_gi_bleed")
summary_attrition <- summariseCohortAttrition(cdm$medications_gi_bleed)
plotCohortAttrition(summary_attrition, cohortId = 1)
summary_attrition <- summariseCohortAttrition(cdm$warfarin_gi_bleed)
plotCohortAttrition(summary_attrition)
```

The flow chart above illustrates the changes to cohort 1 when restricted to only include individuals who have had events of GI bleeding at least once before the cohort start date. 2,296 individuals and 8,765 records were excluded.

Instead of requiring that individuals have events of GI bleeding, we could instead require that they don't have any events of it. In this case we can again use the `requireConceptIntersect()` function, but this time set the intersections argument to 0 to require individuals without past events of GI bleeding.

```{r}
cdm$medications_no_gi_bleed <- cdm$medications %>%
cdm$warfarin_no_gi_bleed <- cdm$warfarin %>%
requireConceptIntersect(intersections = 0,
conceptSet = list("gi_bleed" = 192671),
indexDate = "cohort_start_date",
window = c(-Inf, 0),
name = "medications_no_gi_bleed")
name = "warfarin_no_gi_bleed")
summary_attrition <- summariseCohortAttrition(cdm$medications_no_gi_bleed)
plotCohortAttrition(summary_attrition, cohortId = 1)
summary_attrition <- summariseCohortAttrition(cdm$warfarin_no_gi_bleed)
plotCohortAttrition(summary_attrition)
```

The flow chart above illustrates the changes to cohort 1 when restricted to only include individuals who have not had events of GI bleeding before the cohort start date. 36 individuals and 600 records were excluded.

## Restrictions on presence in clinical tables

A clinical table is a table which contains 'raw' clinical data. We can use clinical tables to filter our cohorts using the `requireTableIntersect()` function. This will allow us to filter individuals in the medications cohort based on whether they have intersections with the GI bleed clinical table or not.

```{r, include = FALSE}
cdm$medications <- conceptCohort(cdm = cdm,
conceptSet = list("diclofenac" = 1124300,
"acetaminophen" = 1127433),
name = "medications")
cdm$gi_bleed <- conceptCohort(cdm = cdm,
conceptSet = list("gi_bleed" = 192671),
name = "gi_bleed")
```

```{r}
cdm$medications_gi_bleed <- cdm$medications %>%
requireTableIntersect(tableName = "gi_bleed",
indexDate = "cohort_start_date",
window = c(-Inf, 0),
name = "medications_gi_bleed")
summary_attrition <- summariseCohortAttrition(cdm$medications_gi_bleed)
plotCohortAttrition(summary_attrition, cohortId = 1)
```

The flow chart above illustrates the changes to cohort 1 when restricted to only include individuals who intersect with the GI bleeding clinical table at least once before the cohort start date. 2,296 individuals and 8,765 records were excluded.

Instead of requiring that individuals intersect with the GI bleed clinical table, we could instead require that they don't intersect with it. In this case we can again use the `requireCohortIntersect()` function, but this time set the intersections argument to 0 to require individuals' absence in the GI bleed clinical table.
We can also impose requirements around individuals presence (or absence) in clinical tables in the OMOP CDM using the `requireTableIntersect()` function. Here for example we reuire that individuals in our warfarin cohort have at least one prior record in the visit occurrence table.

```{r}
cdm$medications_no_gi_bleed <- cdm$medications %>%
requireTableIntersect(tableName = "gi_bleed",
cdm$warfarin_visit <- cdm$warfarin %>%
requireTableIntersect(tableName = "visit_occurrence",
indexDate = "cohort_start_date",
window = c(-Inf, 0),
name = "medications_no_gi_bleed",
intersections = 0)
summary_attrition <- summariseCohortAttrition(cdm$medications_no_gi_bleed)
plotCohortAttrition(summary_attrition, cohortId = 1)
```

The flow chart above illustrates the changes to cohort 1 when restricted to only include individuals who have no intersects with the GI bleeding clinical table before the cohort start date. 36 individuals and 600 records were excluded.

## Restrictions on deaths

We could require that individuals in our medication cohorts are seen to have (or not have) a death. To do this we can use the `requireDeathFlag()` function, requiring that individuals are seen (or not seen) to have died after the cohort start date.

```{r, include = FALSE}
cdm$medications <- conceptCohort(cdm = cdm,
conceptSet = list("diclofenac" = 1124300,
"acetaminophen" = 1127433),
name = "medications")
cdm$gi_bleed <- conceptCohort(cdm = cdm,
conceptSet = list("gi_bleed" = 192671),
name = "gi_bleed")
```

```{r}
cdm$medications_deaths <- cdm$medications %>%
requireDeathFlag(window = c(0,Inf),
name = "medications_deaths")
window = c(-Inf, -1),
name = "warfarin_visit")
summary_attrition <- summariseCohortAttrition(cdm$medications_deaths)
plotCohortAttrition(summary_attrition, cohortId = 1)
summary_attrition <- summariseCohortAttrition(cdm$warfarin_visit)
plotCohortAttrition(summary_attrition)
```

The flow chart above illustrates the changes to cohort 1 when restricted to only include individuals who died after the cohort start date. None of the individuals in cohort 1 died and therefore they are all excluded from this cohort.

To exclude individuals who died we add the argument 'negate = TRUE' to the function `requireDeathFlag()`.

```{r}
cdm$medications_no_deaths <- cdm$medications %>%
requireDeathFlag(window = c(0,Inf),
name = "medications_no_deaths",
negate = TRUE)
summary_attrition <- summariseCohortAttrition(cdm$medications_no_deaths)
plotCohortAttrition(summary_attrition, cohortId = 1)
```

The flow chart above illustrates the changes to cohort 1 when restricted to only include individuals who did not die after the cohort start date. None of the individuals in cohort 1 died and therefore no one was excluded.

0 comments on commit 9e42a9d

Please sign in to comment.