PatientLevelPrediction icon indicating copy to clipboard operation
PatientLevelPrediction copied to clipboard

Cohort covariates not working

Open lhjohn opened this issue 1 year ago • 2 comments

Describe the bug An error is shown (Error: No method asJSON S3 class: call) when saving PLP data that uses cohort covariates. The problems occurs a step earlier during getPlpData().

Additional context The problem occurs once calling getPlpData() for a covariate setting that includes cohort covariates. getPlpData() calls FeatureExtraction::getDbCovariateData() where in line #155 the metaData attribute is not properly assembled. Each cohort covariate's meta data is being nested into a single list, rather than having a list of meta datas.

I also remember that with about 10 cohort covariates it worked fine for me about 6-12 months ago and there have been no changes in the meantime. I assume the problem existed back then, but since I am now using 60+ cohort covariates the error when creating the deeply nested JSON comes up for the first time.

See below for final output for attributes(plpData$covariateData) Not sure whether this is a problem caused by PatientLevelPrediction or FeatureExtraction. nesting-problem

Structure of my reduced covariateSettings object This is just for three cohort covariates, but I am actually using 60+.

covariateSettings <- list(
  FeatureExtraction::createCovariateSettings(
    useDemographicsGender = T, 
    useDemographicsAgeGroup = T
  ), 
  PatientLevelPrediction::createCohortCovariateSettings(
    cohortName = "acetaminophen exposures w 0d prior obsv", 
    settingId = 1, 
    cohortDatabaseSchema = cohortDatabaseSchema, 
    cohortTable = cohortTable, 
    cohortId = 11161, 
    startDay = -365, 
    endDay = 0, 
    analysisId = 11161
  ),
  PatientLevelPrediction::createCohortCovariateSettings(
    cohortName = "First occurrence of Alcoholism", 
    settingId = 1, 
    cohortDatabaseSchema = cohortDatabaseSchema, 
    cohortTable = cohortTable, 
    cohortId = 11117, 
    startDay = -365, 
    endDay = 0, 
    analysisId = 11117
  ),
  PatientLevelPrediction::createCohortCovariateSettings(
    cohortName = "All occurrences of Anemia", 
    settingId = 1, 
    cohortDatabaseSchema = cohortDatabaseSchema, 
    cohortTable = cohortTable, 
    cohortId = 11163, 
    startDay = -365, 
    endDay = 0, 
    analysisId = 11163
  )
)

lhjohn avatar Apr 20 '23 13:04 lhjohn

That's odd. The aggregation of metaData should be done in FE but perhaps the metaData is the wrong format? I need to look into FE to see what it does with the metaData.

jreps avatar Apr 20 '23 18:04 jreps

The metaData part looks to be copied from the FE docs: http://ohdsi.github.io/FeatureExtraction/articles/CreatingCustomCovariateBuilders.html - so I think this must be a FE bug?

jreps avatar Apr 20 '23 18:04 jreps