OHDSI / Capr

Cohort definition Application Programming in R
https://ohdsi.github.io/Capr
Apache License 2.0
15 stars 11 forks source link

Example (or tips) for using age() in defining a cohort within atttrition()? #81

Closed pa-nathaniel closed 1 year ago

pa-nathaniel commented 1 year ago

I'm interested in applying inclusion criteria "is at least 18 at index"

I bet I want to leverage the age() function (https://github.com/OHDSI/Capr/blob/fa03ba051993380a3c69a3b5a6c23273a2cdc390/R/attributes-op.R#L328-L343), but I'm struggling a bit to figure out how to use it in an example

I looked at the examples in https://ohdsi.github.io/Capr/articles/Examples.html but didn't find one. Also couldn't seem to find one anywhere else in the repo.

Any tips? Thanks!!

pa-nathaniel commented 1 year ago

I just found some relevant documentation in at https://github.com/OHDSI/Capr/blob/fa03ba051993380a3c69a3b5a6c23273a2cdc390/vignettes/capr_objects.Rmd#L101-L106 I'll keep learning and post an answer if I can solve it!

mdlavallee92 commented 1 year ago

@pa-nathaniel thanks for your question. you have indeed found a bug. If you want to observe the attrition based on age you can add the age as a demographic criteria to a group. This is what happens in ATLAS. I need to add a container that holds the demographic criteria to apply it to the group. A group must take in a criteria class. Code would look as such:

library(Capr)

  t1dConceptSet <- cs(descendants(195771), name = "T1D") 

  cd <- cohort(
    entry = entry(
      t1dConceptSet,
      observationWindow = continuousObservation(priorDays = 365L),
      primaryCriteriaLimit = "All"
    ),
    attrition = attrition(
      'atLeast18' = withAll(
        demographic(age(gte(18L))) # function to add
      )
    )
  )
pa-nathaniel commented 1 year ago

Ah interesting, I thought I had solved it yesterday evening by doing something like the code below. Would this not do it?

library(Capr)

 t1dConceptSet <- cs(descendants(195771), name = "T1D") 

 cd <- cohort(
    entry = entry(
      t1dConceptSet,
      observationWindow = continuousObservation(priorDays = 365L),
      primaryCriteriaLimit = "All"
    ),
    attrition = attrition(
     "At least 18 at entry" = withAll(
      atLeast(
        1,
        conditionOccurrence(
          t1dConceptSet,
          age(gte(18)), firstOccurrence()
        )
      )
  )
mdlavallee92 commented 1 year ago

If you are using age as an attribute to a condition this is indeed correct. However, circe allows you to use a demographic attribute as a point of attrition. This is not covered in Capr v2 and needs to be added.

pa-nathaniel commented 1 year ago

Ah great glad I wasn't too far off, thanks!