OHDSI Home | Forums | Wiki | Github

Building package for incidence rate calculation with accompanied Shiny output

Dear all,

I’m new to OHDSI and is hoping to pick some brain you guys. I’m trying to build a study package that calculate the incidence rate with a shiny app output, but don’t know where to start. I know that with Population Level Estimation Analysis and Patient level prediction one can define the analysis in ATLAS and download the R package from there, but I don’t see a similar option for Incidence rate.

Any suggesstions will be greatly appreciated!

ATLAs doesn’t do that in R, but directly in SQL. You can find it in the Utilities tab under SQL.

@Chris_Knoll is currently working on the CohortIncidence package that should provide that functionality.

Yes, the package is found in the CohortIncidence repository, and the object model that defines the IR analysis design can be found in this class definition (which you can the high level ‘parts’ of the overall analysis, and you can navigate in the repository to find out how the ‘pieces’ are defined (for example, TimeAtRisk).

The vignette in the deveop branch is complete, and should be a good place to start to see how it works.

I’m working on an example that does an end-to-end execution on Eunomia.

Thanks @Chris_Knoll. Tested the Package against our Database and it works well.
I’m excited for the complete version with subgroup stratifications :blush:

You can use it now if you pull down the issue-8 branch. The vignette also has a simplified form to execute the analysis which may be helpful.

1 Like

Do you have an end to end example of the R script that you used that you can share?

The vitgnette pdf has cut off text. Can you re-upload so all text is visible?

Do you have an example of end-to-end execution?

I’m not sure if you checked recently, but the git-pages site is up to date with the latest release, and you see an end-to-end example of the execution in this article.

It will just produce a table of results, however. I have a few scripts that will plot the results however, and can share them here:

# assuming you have your irDesign and buildOptions created, execute the analysis
# and store results in executeResults

executeResults <- CohortIncidence::executeAnalysis(connectionDetails = connectionDetailsSample,
                                                   incidenceDesign = irDesign,
                                                   buildOptions = buildOptions)


# filter to the overall rates: no age, gender or year stratification
overall <- executeResults %>% filter(is.na(AGE_ID) & is.na(GENDER_ID) & is.na(START_YEAR)) %>% arrange(OUTCOME_ID)
View(overall)

# filter to by gender
byGender <- executeResults %>% filter(is.na(AGE_ID) & !is.na(GENDER_ID) & is.na(START_YEAR)) %>% arrange(OUTCOME_ID, GENDER_ID)
View(byGender)

# filter to by year
byYear <- executeResults %>% filter(is.na(AGE_ID) & is.na(GENDER_ID) & !is.na(START_YEAR)) %>% arrange(OUTCOME_ID, START_YEAR) 
View(byYear)
plotByYear(byYear)

# filter to by gender, by year
View(executeResults %>% filter(is.na(AGE_ID) & !is.na(GENDER_ID) & !is.na(START_YEAR)) %>% arrange(OUTCOME_ID, START_YEAR)  )
plotByGenderByYear(executeResults)

View(executeResults %>% filter(!is.na(AGE_ID) & is.na(GENDER_ID) & is.na(START_YEAR)))
plotByAge(executeResults)


View(executeResults %>% filter(!is.na(AGE_ID) & !is.na(GENDER_ID) & is.na(START_YEAR)))
plotByAgeByGender(executeResults)

These are the plotting functions that were used in the above:

plotByGenderByYear <- function(irData) {
  plotData <- irData %>% filter(is.na(AGE_ID) & !is.na(GENDER_ID) & !is.na(START_YEAR)) %>% 
    arrange(OUTCOME_ID, START_YEAR)
  
  ggplot2::ggplot(plotData, ggplot2::aes(x = START_YEAR, y = INCIDENCE_RATE_P100PY, color=GENDER_NAME, shape=as.factor(OUTCOME_NAME))) +
    ggplot2::geom_point(size=3) 
}

plotByYear <- function(irData) {
  plotData <- irData %>% filter(is.na(AGE_ID) & is.na(GENDER_ID) & !is.na(START_YEAR)) %>% 
    arrange(OUTCOME_ID, START_YEAR)
  
  ggplot2::ggplot(plotData, ggplot2::aes(x = START_YEAR, y = INCIDENCE_RATE_P100PY, shape=as.factor(OUTCOME_NAME))) +
    ggplot2::geom_point(size = 3)
}

plotByAge <- function(irData) {
  plotData <- irData %>% filter(!is.na(AGE_ID) & is.na(GENDER_ID) & is.na(START_YEAR)) %>% 
    arrange(OUTCOME_ID, AGE_ID) %>%
    mutate(AGE_X = forcats::fct_reorder(factor(AGE_GROUP_NAME), AGE_ID))
  
  ggplot2::ggplot(plotData, ggplot2::aes(x = AGE_X, y = INCIDENCE_RATE_P100PY, shape=as.factor(OUTCOME_NAME))) +
    ggplot2::geom_point(size = 3, position = ggplot2::position_dodge(width=.5))
}

plotByAgeByGender <- function(irData) {
  plotData <- irData %>% filter(!is.na(AGE_ID) & !is.na(GENDER_ID) & is.na(START_YEAR)) %>% 
    arrange(OUTCOME_ID, AGE_ID) %>%
    mutate(AGE_X = forcats::fct_reorder(factor(AGE_GROUP_NAME), AGE_ID))
  
  ggplot2::ggplot(plotData, ggplot2::aes(x = AGE_X, y = INCIDENCE_RATE_P100PY, color=GENDER_NAME, shape=as.factor(OUTCOME_NAME))) +
    ggplot2::geom_point(size = 3, position = ggplot2::position_dodge(width=.5)) + ggplot2::labs(x = "Age", y = "Events per 100 Person-Years", shape = "Outcome", color = "Gender") + ggplot2::scale_color_discrete()
}

t