OHDSI / SelfControlledCaseSeries

An R package for performing Self-Controlled Case Series (SCCS) analyses in an observational database in the OMOP Common Data Model.
http://ohdsi.github.io/SelfControlledCaseSeries
13 stars 8 forks source link

`runSccsAnalyses` included multiple exposures #27

Closed Xintong-Li-ZnCu closed 2 years ago

Xintong-Li-ZnCu commented 2 years ago

When I ran runSccsAnalyses with a exposureOutcomeList, the outcome models included all exposure cohorts into one model, though I have only one exposure and one outcome id in each e/o pair.

> eoList
[[1]]
$exposureId
[1] 1

$outcomeId
[1] 1

attr(,"class")
[1] "exposureOutcome"

[[2]]
$exposureId
[1] 2

$outcomeId
[1] 1

attr(,"class")
[1] "exposureOutcome"
> SccsModel_e1_o1
SccsModel object

Outcome ID: 1

Outcome count:
  outcomeSubjects outcomeEvents outcomeObsPeriods
1           97399         97399             97399

Estimates:
# A tibble: 22 x 7
   Name                                             ID Estimate LB95CI UB95CI   LogRr SeLogRr
   <chr>                                         <dbl>    <dbl>  <dbl>  <dbl>   <dbl>   <dbl>
 1 vaccine 0: Exposure cohort 1                   1000    0.552 0.0777  1.84  -0.594    0.807
 2 vaccine 0: Exposure cohort 1                   1000    0.552 0.0777  1.84  -0.594    0.807
 3 vaccine 0: Outcome cohort 1                    1000    0.552 0.0777  1.84  -0.594    0.807
 4 vaccine 0: Outcome cohort 1                    1000    0.552 0.0777  1.84  -0.594    0.807
 5 vaccine 0: Exposure cohort 2                   1001    0.370 0.0366  3.68  -0.994    1.18 
 6 vaccine 0: Exposure cohort 2                   1001    0.370 0.0366  3.68  -0.994    1.18 
 7 vaccine 0: Outcome cohort 2                    1001    0.370 0.0366  3.68  -0.994    1.18 
 8 vaccine 0: Outcome cohort 2                    1001    0.370 0.0366  3.68  -0.994    1.18 
 9 post-vaccine 21d: Exposure cohort 1, day 1-7   1002    0.409 0.137   0.620 -0.894    0.386

I don't get why there is Exposure cohort 2 as I only want to study single e/o id.

schuemie commented 2 years ago

Could you provide the analysis settings you're using? Especially your calls to createEraCovariateSettings().

Xintong-Li-ZnCu commented 2 years ago

please see below.

createStudyPopulationArgs1 <- SelfControlledCaseSeries::createCreateStudyPopulationArgs( firstOutcomeOnly = TRUE)

covarVax <- createEraCovariateSettings(label = "post-vaccine 21d",
                                         startAnchor = "era start" ,
                                         start = 1,
                                         end = 21,
                                         endAnchor = "era start",
                                         splitPoints = c(7,14))

sameday <- createEraCovariateSettings(label = "vaccine 0",
                                      #    includeEraIds = VaxAZ,
                                      startAnchor = "era start" ,
                                      start = 0,
                                      end = 0,
                                      endAnchor = "era start")

covarPreVax <- createEraCovariateSettings(label = "Pre-exposure 21d",
                                            startAnchor = "era start" ,
                                            start = -21,
                                            end = -1,
                                            endAnchor = "era start")

createSccsIntervalDataArgs1 <- createCreateSccsIntervalDataArgs(
  eraCovariateSettings = list(sameday,
                              covarVax,
                              covarPreVax))

fitSccsModelArgs <- createFitSccsModelArgs(control = createControl(threads = parallel::detectCores()-1))

sccsAnalysis1 <- createSccsAnalysis(analysisId = 1,
                                    description = "Simplest model",
                                    getDbSccsDataArgs = getDbSccsDataArgs1,
                                    createStudyPopulationArgs = createStudyPopulationArgs1,
                                    createSccsIntervalDataArgs = createSccsIntervalDataArgs1,
                                    fitSccsModelArgs = fitSccsModelArgs)
schuemie commented 2 years ago

Ah, yes, I know this is a bit counterintuitive, but you need to tell the package which exposures to use for which 'era covariate'. Right now, no exposures are specified, and the default is to use all exposures found in the data.

Since you're using the era covariate settings in runAnalyses, you can't provide the actual exposure ID (because it will be different for each exposure-outcome combination), so you have to point to the variable containing the exposure ID. (See this part of the vignette). For example, for covarVax, you'd need to change the code to:

covarVax <- createEraCovariateSettings(label = "post-vaccine 21d",
                                       includeEraIds = "exposureId",
                                       startAnchor = "era start" ,
                                       start = 1,
                                       end = 21,
                                       endAnchor = "era start",
                                       splitPoints = c(7,14))

(Note the includeEraIds argument)

The reason for this complicated way of working is because it allows you to include different types of exposures into a single model (e.g. you could have separate covariates for the first and second dose of a vaccine, if you have separate cohorts for those two exposures). See for example this code in Eumaeus, together with this code)

Xintong-Li-ZnCu commented 2 years ago

Thank you so much! It worked ;)