Calculating prevalence

Introduction

Prevalence is the total number of people with an ongoing health-related event, such as a medical condition or medication use, at a particular time or during a given period divided by the population at risk. In the previous vignettes we have seen how we can identify a denominator population and define and instantiate an outcome cohort. Prevalence then can be calculated to describe the proportion of people in the denominator population who are in the outcome cohort at a specified time point (point prevalence) or over a given time interval (period prevalence).

In the first plot below, we can We can see at time t+2 that 2 out of 5 people were in an outcome cohort, giving a point prevalence of 40%. In the second figure, period prevalence between t+2 and t+3 was also 40%. However for period prevalence between t and t+1, what do we do with those people who only contributed some time during the period? If we included them we´ll have a period prevalence of 20%, whereas if we require that everyone is observed for the full period to contribute then we´ll have a period prevalence of 33%.

Outcome definition

Outcome cohorts are defined externally. When creating outcome cohorts for estimating prevalence, important considerations relate to whether to restrict events to the first occurrence in an individuals history or not and how cohort exit is defined. These decisions will necessarily be based on the nature of the proposed outcome (e.g., whether it is an acute or chronic condition) and the research question being investigated.

In addition, it is typically not recommended to include exclusion requirements when creating outcome cohorts. Restrictions on patient characteristics can be specified when identifying the denominator cohort using generateDenominatorCohortSet() or generateTargetDenominatorCohortSet()

Using estimatePointPrevalence() and estimatePeriodPrevalence()

estimatePointPrevalence() and estimatePeriodPrevalence() are the functions we use to estimate prevalence. To demonstrate its use, let´s load the IncidencePrevalence package (along with a couple of packages to help for subsequent plots) and generate 50,000 example patients using the mockIncidencePrevalenceRef() function from whom we´ll create a denominator population without adding any restrictions other than a study period.

library(IncidencePrevalence)
library(dplyr)
library(tidyr)

cdm <- mockIncidencePrevalenceRef(
  sampleSize = 20000,
  outPre = 0.3
)

cdm <- generateDenominatorCohortSet(
  cdm = cdm, name = "denominator",
  cohortDateRange = c(as.Date("2008-01-01"), as.Date("2012-01-01")),
  ageGroup = list(c(0, 150)),
  sex = "Both",
  daysPriorObservation = 0
)
#> ℹ Creating denominator cohorts
#> ✔ Cohorts created in 0 min and 3 sec

cdm$denominator %>%
  glimpse()
#> Rows: ??
#> Columns: 4
#> Database: DuckDB v0.9.2 [eburn@Windows 10 x64:R 4.2.1/:memory:]
#> $ cohort_definition_id <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1…
#> $ subject_id           <chr> "1", "2", "3", "6", "8", "10", "11", "12", "13", …
#> $ cohort_start_date    <date> 2008-01-01, 2008-01-01, 2008-01-01, 2008-01-01, …
#> $ cohort_end_date      <date> 2012-01-01, 2012-01-01, 2012-01-01, 2011-08-09, …

Using estimatePointPrevalence()

Let´s first calculate point prevalence on a yearly basis.

prev <- estimatePointPrevalence(
  cdm = cdm,
  denominatorTable = "denominator",
  outcomeTable = "outcome",
  interval = "Years",
  minCellCount = 0
)

prev %>%
  glimpse()
#> Rows: 5
#> Columns: 29
#> $ analysis_id                             <chr> "1", "1", "1", "1", "1"
#> $ prevalence_start_date                   <date> 2008-01-01, 2009-01-01, 2010-0…
#> $ prevalence_end_date                     <date> 2008-01-01, 2009-01-01, 2010-…
#> $ n_cases                                 <int> 1, 0, 0, 0, 1
#> $ n_population                            <int> 13910, 13672, 13446, 13194, 1…
#> $ prevalence                              <dbl> 7.189073e-05, 0.000000e+00, 0.…
#> $ prevalence_95CI_lower                   <dbl> 1.269059e-05, 0.000000e+00, 2.…
#> $ prevalence_95CI_upper                   <dbl> 0.0004071402, 0.0002808938, 0.…
#> $ population_obscured                     <chr> "FALSE", "FALSE", "FALSE", "FA…
#> $ cases_obscured                          <chr> "FALSE", "FALSE", "FALSE", "FA…
#> $ result_obscured                         <chr> "FALSE", "FALSE", "FALSE", "FA…
#> $ outcome_cohort_id                       <int> 1, 1, 1, 1, 1
#> $ outcome_cohort_name                     <chr> "cohort_1", "cohort_1", "cohor…
#> $ analysis_type                           <chr> "point", "point", "point", "po…
#> $ analysis_interval                       <chr> "years", "years", "years", "ye…
#> $ analysis_complete_database_intervals    <lgl> FALSE, FALSE, FALSE, FALSE, FA…
#> $ analysis_time_point                     <chr> "start", "start", "start", "st…
#> $ analysis_full_contribution              <lgl> FALSE, FALSE, FALSE, FALSE, FA…
#> $ analysis_min_cell_count                 <dbl> 0, 0, 0, 0, 0
#> $ denominator_cohort_id                   <int> 1, 1, 1, 1, 1
#> $ denominator_cohort_name                 <chr> "denominator_cohort_1", "denom…
#> $ denominator_age_group                   <chr> "0 to 150", "0 to 150", "0 to …
#> $ denominator_sex                         <chr> "Both", "Both", "Both", "Both"…
#> $ denominator_days_prior_observation      <dbl> 0, 0, 0, 0, 0
#> $ denominator_start_date                  <date> 2008-01-01, 2008-01-01, 2008-0…
#> $ denominator_end_date                    <date> 2012-01-01, 2012-01-01, 2012-0…
#> $ denominator_target_cohort_definition_id <int> NA, NA, NA, NA, NA
#> $ denominator_target_cohort_name          <lgl> NA, NA, NA, NA, NA
#> $ cdm_name                                <chr> "mock", "mock", "mock", "mock"…

plotPrevalence(prev, ylim = c(0, NA))

We can also calculate point prevalence by calendar month.

prev <- estimatePointPrevalence(
  cdm = cdm,
  denominatorTable = "denominator",
  outcomeTable = "outcome",
  interval = "Months",
  minCellCount = 0
)

prev %>%
  glimpse()
#> Rows: 49
#> Columns: 29
#> $ analysis_id                             <chr> "1", "1", "1", "1", "1", "1", …
#> $ prevalence_start_date                   <date> 2008-01-01, 2008-02-01, 2008-…
#> $ prevalence_end_date                     <date> 2008-01-01, 2008-02-01, 2008-…
#> $ n_cases                                 <int> 1, 1, 0, 0, 2, 0, 0, 1, 0, 0, …
#> $ n_population                            <int> 13910, 13887, 13868, 13854, 13…
#> $ prevalence                              <dbl> 7.189073e-05, 7.200979e-05, 0.…
#> $ prevalence_95CI_lower                   <dbl> 1.269059e-05, 1.271161e-05, 0.…
#> $ prevalence_95CI_upper                   <dbl> 0.0004071402, 0.0004078143, 0.…
#> $ population_obscured                     <chr> "FALSE", "FALSE", "FALSE", "FA…
#> $ cases_obscured                          <chr> "FALSE", "FALSE", "FALSE", "FA…
#> $ result_obscured                         <chr> "FALSE", "FALSE", "FALSE", "FA…
#> $ outcome_cohort_id                       <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, …
#> $ outcome_cohort_name                     <chr> "cohort_1", "cohort_1", "cohor…
#> $ analysis_type                           <chr> "point", "point", "point", "po…
#> $ analysis_interval                       <chr> "months", "months", "months", …
#> $ analysis_complete_database_intervals    <lgl> FALSE, FALSE, FALSE, FALSE, FA…
#> $ analysis_time_point                     <chr> "start", "start", "start", "st…
#> $ analysis_full_contribution              <lgl> FALSE, FALSE, FALSE, FALSE, FA…
#> $ analysis_min_cell_count                 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
#> $ denominator_cohort_id                   <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, …
#> $ denominator_cohort_name                 <chr> "denominator_cohort_1", "denom…
#> $ denominator_age_group                   <chr> "0 to 150", "0 to 150", "0 to …
#> $ denominator_sex                         <chr> "Both", "Both", "Both", "Both"…
#> $ denominator_days_prior_observation      <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
#> $ denominator_start_date                  <date> 2008-01-01, 2008-01-01, 2008-…
#> $ denominator_end_date                    <date> 2012-01-01, 2012-01-01, 2012-…
#> $ denominator_target_cohort_definition_id <int> NA, NA, NA, NA, NA, NA, NA, NA…
#> $ denominator_target_cohort_name          <lgl> NA, NA, NA, NA, NA, NA, NA, NA…
#> $ cdm_name                                <chr> "mock", "mock", "mock", "mock"…

plotPrevalence(prev, ylim = c(0, NA))

By using the estimatePointPrevalence() function, we can further specify where to compute point prevalence in each time interval (start, middle, end). By default, this parameter is set to start. But we can use middle instead like so:

prev <- estimatePointPrevalence(
  cdm = cdm,
  denominatorTable = "denominator",
  outcomeTable = "outcome",
  interval = "Years",
  timePoint = "middle",
  minCellCount = 0
)

prev %>%
  glimpse()
#> Rows: 4
#> Columns: 29
#> $ analysis_id                             <chr> "1", "1", "1", "1"
#> $ prevalence_start_date                   <date> 2008-07-01, 2009-07-01, 2010-0…
#> $ prevalence_end_date                     <date> 2008-07-01, 2009-07-01, 2010-…
#> $ n_cases                                 <int> 0, 0, 1, 0
#> $ n_population                            <int> 13798, 13562, 13324, 13081
#> $ prevalence                              <dbl> 0.000000e+00, 0.000000e+00, 7…
#> $ prevalence_95CI_lower                   <dbl> -2.710505e-20, 0.000000e+00, 1…
#> $ prevalence_95CI_upper                   <dbl> 0.0002783294, 0.0002831714, 0.…
#> $ population_obscured                     <chr> "FALSE", "FALSE", "FALSE", "FA…
#> $ cases_obscured                          <chr> "FALSE", "FALSE", "FALSE", "FA…
#> $ result_obscured                         <chr> "FALSE", "FALSE", "FALSE", "FA…
#> $ outcome_cohort_id                       <int> 1, 1, 1, 1
#> $ outcome_cohort_name                     <chr> "cohort_1", "cohort_1", "cohor…
#> $ analysis_type                           <chr> "point", "point", "point", "po…
#> $ analysis_interval                       <chr> "years", "years", "years", "ye…
#> $ analysis_complete_database_intervals    <lgl> FALSE, FALSE, FALSE, FALSE
#> $ analysis_time_point                     <chr> "middle", "middle", "middle", …
#> $ analysis_full_contribution              <lgl> FALSE, FALSE, FALSE, FALSE
#> $ analysis_min_cell_count                 <dbl> 0, 0, 0, 0
#> $ denominator_cohort_id                   <int> 1, 1, 1, 1
#> $ denominator_cohort_name                 <chr> "denominator_cohort_1", "denom…
#> $ denominator_age_group                   <chr> "0 to 150", "0 to 150", "0 to …
#> $ denominator_sex                         <chr> "Both", "Both", "Both", "Both"
#> $ denominator_days_prior_observation      <dbl> 0, 0, 0, 0
#> $ denominator_start_date                  <date> 2008-01-01, 2008-01-01, 2008-0…
#> $ denominator_end_date                    <date> 2012-01-01, 2012-01-01, 2012-0…
#> $ denominator_target_cohort_definition_id <int> NA, NA, NA, NA
#> $ denominator_target_cohort_name          <lgl> NA, NA, NA, NA
#> $ cdm_name                                <chr> "mock", "mock", "mock", "mock"

plotPrevalence(prev, ylim = c(0, NA))

Using estimatePeriodPrevalence()

To calculate period prevalence by year (i.e. each period is a calendar year)

prev <- estimatePeriodPrevalence(
  cdm = cdm,
  denominatorTable = "denominator",
  outcomeTable = "outcome",
  interval = "Years",
  minCellCount = 0
)

prev %>%
  glimpse()
#> Rows: 4
#> Columns: 29
#> $ analysis_id                             <chr> "1", "1", "1", "1"
#> $ prevalence_start_date                   <date> 2008-01-01, 2009-01-01, 2010-0…
#> $ prevalence_end_date                     <date> 2008-12-31, 2009-12-31, 2010-…
#> $ n_cases                                 <int> 62, 77, 76, 72
#> $ n_population                            <int> 13910, 13672, 13446, 13194
#> $ prevalence                              <dbl> 0.004457225, 0.005631949, 0.0…
#> $ prevalence_95CI_lower                   <dbl> 0.003478770, 0.004508929, 0.00…
#> $ prevalence_95CI_upper                   <dbl> 0.005709307, 0.007032698, 0.00…
#> $ population_obscured                     <chr> "FALSE", "FALSE", "FALSE", "FA…
#> $ cases_obscured                          <chr> "FALSE", "FALSE", "FALSE", "FA…
#> $ result_obscured                         <chr> "FALSE", "FALSE", "FALSE", "FA…
#> $ outcome_cohort_id                       <int> 1, 1, 1, 1
#> $ outcome_cohort_name                     <chr> "cohort_1", "cohort_1", "cohor…
#> $ analysis_type                           <chr> "period", "period", "period", …
#> $ analysis_interval                       <chr> "years", "years", "years", "ye…
#> $ analysis_complete_database_intervals    <lgl> TRUE, TRUE, TRUE, TRUE
#> $ analysis_time_point                     <chr> "start", "start", "start", "st…
#> $ analysis_full_contribution              <lgl> FALSE, FALSE, FALSE, FALSE
#> $ analysis_min_cell_count                 <dbl> 0, 0, 0, 0
#> $ denominator_cohort_id                   <int> 1, 1, 1, 1
#> $ denominator_cohort_name                 <chr> "denominator_cohort_1", "denom…
#> $ denominator_age_group                   <chr> "0 to 150", "0 to 150", "0 to …
#> $ denominator_sex                         <chr> "Both", "Both", "Both", "Both"
#> $ denominator_days_prior_observation      <dbl> 0, 0, 0, 0
#> $ denominator_start_date                  <date> 2008-01-01, 2008-01-01, 2008-0…
#> $ denominator_end_date                    <date> 2012-01-01, 2012-01-01, 2012-0…
#> $ denominator_target_cohort_definition_id <int> NA, NA, NA, NA
#> $ denominator_target_cohort_name          <lgl> NA, NA, NA, NA
#> $ cdm_name                                <chr> "mock", "mock", "mock", "mock"

plotPrevalence(prev, ylim = c(0.1, 0.3))

To calculate period prevalence by month (i.e. each period is a calendar month)

prev <- estimatePeriodPrevalence(
  cdm = cdm,
  denominatorTable = "denominator",
  outcomeTable = "outcome",
  interval = "Months",
  minCellCount = 0
)

prev %>%
  glimpse()
#> Rows: 48
#> Columns: 29
#> $ analysis_id                             <chr> "1", "1", "1", "1", "1", "1", …
#> $ prevalence_start_date                   <date> 2008-01-01, 2008-02-01, 2008-…
#> $ prevalence_end_date                     <date> 2008-01-31, 2008-02-29, 2008-…
#> $ n_cases                                 <int> 6, 6, 5, 7, 5, 2, 5, 3, 8, 5, …
#> $ n_population                            <int> 13910, 13887, 13868, 13854, 13…
#> $ prevalence                              <dbl> 0.0004313444, 0.0004320588, 0.…
#> $ prevalence_95CI_lower                   <dbl> 1.977035e-04, 1.980310e-04, 1.…
#> $ prevalence_95CI_upper                   <dbl> 0.0009408360, 0.0009423937, 0.…
#> $ population_obscured                     <chr> "FALSE", "FALSE", "FALSE", "FA…
#> $ cases_obscured                          <chr> "FALSE", "FALSE", "FALSE", "FA…
#> $ result_obscured                         <chr> "FALSE", "FALSE", "FALSE", "FA…
#> $ outcome_cohort_id                       <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, …
#> $ outcome_cohort_name                     <chr> "cohort_1", "cohort_1", "cohor…
#> $ analysis_type                           <chr> "period", "period", "period", …
#> $ analysis_interval                       <chr> "months", "months", "months", …
#> $ analysis_complete_database_intervals    <lgl> TRUE, TRUE, TRUE, TRUE, TRUE, …
#> $ analysis_time_point                     <chr> "start", "start", "start", "st…
#> $ analysis_full_contribution              <lgl> FALSE, FALSE, FALSE, FALSE, FA…
#> $ analysis_min_cell_count                 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
#> $ denominator_cohort_id                   <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, …
#> $ denominator_cohort_name                 <chr> "denominator_cohort_1", "denom…
#> $ denominator_age_group                   <chr> "0 to 150", "0 to 150", "0 to …
#> $ denominator_sex                         <chr> "Both", "Both", "Both", "Both"…
#> $ denominator_days_prior_observation      <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
#> $ denominator_start_date                  <date> 2008-01-01, 2008-01-01, 2008-…
#> $ denominator_end_date                    <date> 2012-01-01, 2012-01-01, 2012-…
#> $ denominator_target_cohort_definition_id <int> NA, NA, NA, NA, NA, NA, NA, NA…
#> $ denominator_target_cohort_name          <lgl> NA, NA, NA, NA, NA, NA, NA, NA…
#> $ cdm_name                                <chr> "mock", "mock", "mock", "mock"…

plotPrevalence(prev, ylim = c(0, NA))

When using the estimatePeriodPrevalence() function, we can set the fullContribution parameter to decide whether individuals are required to be present in the database throughout the interval of interest in order to be included (fullContribution=TRUE). If not, individuals will only be required to be present for one day of the interval to contribute (fullContribution=FALSE), which would be specified like so:

prev <- estimatePeriodPrevalence(
  cdm = cdm,
  denominatorTable = "denominator",
  outcomeTable = "outcome",
  interval = "Months",
  fullContribution = FALSE,
  minCellCount = 0
)

prev %>%
  glimpse()
#> Rows: 48
#> Columns: 29
#> $ analysis_id                             <chr> "1", "1", "1", "1", "1", "1", …
#> $ prevalence_start_date                   <date> 2008-01-01, 2008-02-01, 2008-…
#> $ prevalence_end_date                     <date> 2008-01-31, 2008-02-29, 2008-…
#> $ n_cases                                 <int> 6, 6, 5, 7, 5, 2, 5, 3, 8, 5, …
#> $ n_population                            <int> 13910, 13887, 13868, 13854, 13…
#> $ prevalence                              <dbl> 0.0004313444, 0.0004320588, 0.…
#> $ prevalence_95CI_lower                   <dbl> 1.977035e-04, 1.980310e-04, 1.…
#> $ prevalence_95CI_upper                   <dbl> 0.0009408360, 0.0009423937, 0.…
#> $ population_obscured                     <chr> "FALSE", "FALSE", "FALSE", "FA…
#> $ cases_obscured                          <chr> "FALSE", "FALSE", "FALSE", "FA…
#> $ result_obscured                         <chr> "FALSE", "FALSE", "FALSE", "FA…
#> $ outcome_cohort_id                       <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, …
#> $ outcome_cohort_name                     <chr> "cohort_1", "cohort_1", "cohor…
#> $ analysis_type                           <chr> "period", "period", "period", …
#> $ analysis_interval                       <chr> "months", "months", "months", …
#> $ analysis_complete_database_intervals    <lgl> TRUE, TRUE, TRUE, TRUE, TRUE, …
#> $ analysis_time_point                     <chr> "start", "start", "start", "st…
#> $ analysis_full_contribution              <lgl> FALSE, FALSE, FALSE, FALSE, FA…
#> $ analysis_min_cell_count                 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
#> $ denominator_cohort_id                   <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, …
#> $ denominator_cohort_name                 <chr> "denominator_cohort_1", "denom…
#> $ denominator_age_group                   <chr> "0 to 150", "0 to 150", "0 to …
#> $ denominator_sex                         <chr> "Both", "Both", "Both", "Both"…
#> $ denominator_days_prior_observation      <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
#> $ denominator_start_date                  <date> 2008-01-01, 2008-01-01, 2008-…
#> $ denominator_end_date                    <date> 2012-01-01, 2012-01-01, 2012-…
#> $ denominator_target_cohort_definition_id <int> NA, NA, NA, NA, NA, NA, NA, NA…
#> $ denominator_target_cohort_name          <lgl> NA, NA, NA, NA, NA, NA, NA, NA…
#> $ cdm_name                                <chr> "mock", "mock", "mock", "mock"…

plotPrevalence(prev,
  ylim = c(0, 0.07)
)

Stratified analyses

If we specified multiple denominator populations results will be returned for each. Here for example we define three age groups for denominator populations and get three sets of estimates back when estimating prevalence.

cdm <- generateDenominatorCohortSet(
  cdm = cdm, name = "denominator_age_sex",
  cohortDateRange = c(as.Date("2008-01-01"), as.Date("2012-01-01")),
  ageGroup = list(c(0, 39),
                  c(41, 65),
                  c(66, 150)),
  sex = "Both",
  daysPriorObservation = 0
)
#> ℹ Creating denominator cohorts
#> ✔ Cohorts created in 0 min and 5 sec
prev <- estimatePeriodPrevalence(
  cdm = cdm,
  denominatorTable = "denominator_age_sex",
  outcomeTable = "outcome",
  minCellCount = 0
)
#> Getting prevalence for analysis 1 of 3
#> Getting prevalence for analysis 2 of 3
#> Getting prevalence for analysis 3 of 3
#> Time taken: 0 mins and 0 secs

plotPrevalence(prev, facet = "denominator_age_group")

While we specify time-varying stratifications when defining our denominator populations, if we have time-invariant stratifications we can include these at the the estimation stage. To do this we first need to add a new column to our denominator cohort with our stratification variable. Here we´ll add an example stratification just to show the idea. Note, as well as getting stratified results we´ll also get overall results.

cdm$denominator <- cdm$denominator %>% 
  mutate(group = if_else(as.numeric(subject_id)  < 500, "first", "second")) 

prev <- estimatePeriodPrevalence(
  cdm = cdm,
  denominatorTable = "denominator",
  outcomeTable = "outcome",
  strata = "group",
  minCellCount = 0
)
#> Getting prevalence for analysis 1 of 1
#> Time taken: 0 mins and 0 secs

plotPrevalence(prev, 
               facet = "strata_level")

We can also stratify on multiple variables at the same time.

cdm$denominator <- cdm$denominator %>% 
  mutate(group_1 = if_else(as.numeric(subject_id)  < 1500, "first", "second"))  %>% 
  mutate(group_2 = if_else(cohort_start_date  < as.Date("2010-01-01"), 
                           "pre", "post"))

prev <- estimatePeriodPrevalence(
  cdm = cdm,
  denominatorTable = "denominator",
  outcomeTable = "outcome",
  strata = list(c("group_1"), # for just group_1
                c("group_2"), # for just group_2
                c("group_1", "group_2")),  # for group_1 and group_2
  minCellCount = 0
)
#> Getting prevalence for analysis 1 of 1
#> Time taken: 0 mins and 0 secs

plotPrevalence(prev, 
               facet = "strata_level")

Other parameters

In the examples above, we have used calculated prevalence by months and years, but it can be also calculated by weeks, months or for the entire time period observed (overall). In addition, the user can decide whether to include time intervals that are not fully captured in the database (e.g., having data up to June for the last study year when computing period prevalence rates). By default, incidence will only be estimated for those intervals where the database captures all the interval (completeDatabaseIntervals=TRUE).

Given that we can set estimatePointPrevalence() and estimatePeriorPrevalence() to exclude individuals based on certain parameters (e.g., fullContribution), it is important to note that the denominator population used to compute prevalence rates might differ from the one calculated with generateDenominatorCohortSet().

The user can also set the minimum number of events to be reported, below which results will be obscured. By default, results with <5 occurrences are blinded, but if minCellCount=0, all results will be reported. 95 % confidence intervals are calculated using the Wilson Score method. In addition, we can set verbose=TRUE to report progress as code is running. By default, no progress is reported (verbose=FALSE).

Output

estimatePointPrevalence() and estimatePeriorPrevalence() will generate a table with point and period prevalence rates for each of the time intervals studied and for each combination of the parameters set, respectively. Similar to the output obtained by generateDenominatorCohortSet(), the table generated will also include attributes, including tibbles with information on settings and attrition.

prev <- estimatePeriodPrevalence(
  cdm = cdm,
  denominatorTable = "denominator",
  outcomeTable = "outcome",
  interval = "Years",
  fullContribution = c(TRUE, FALSE),
  minCellCount = 0,
  returnParticipants = TRUE
)
prevalenceAttrition(prev)
#> # A tibble: 22 × 25
#>    analysis_id number_records number_subjects reason_id reason  excluded_records
#>    <chr>       <chr>          <chr>               <int> <chr>   <chr>           
#>  1 1           20000          20000                   1 Starti… <NA>            
#>  2 1           20000          20000                   2 Missin… 0               
#>  3 1           20000          20000                   3 Missin… 0               
#>  4 1           20000          20000                   4 Cannot… 0               
#>  5 1           13910          13910                   5 No obs… 6090            
#>  6 1           13910          13910                   6 Doesn'… 0               
#>  7 1           13910          13910                   7 Prior … 0               
#>  8 1           13910          13910                  10 No obs… 0               
#>  9 1           13910          13910                  11 Starti… <NA>            
#> 10 1           13910          13910                  12 Not ob… 0               
#> # ℹ 12 more rows
#> # ℹ 19 more variables: excluded_subjects <chr>, outcome_cohort_id <int>,
#> #   outcome_cohort_name <chr>, analysis_type <chr>, analysis_interval <chr>,
#> #   analysis_complete_database_intervals <lgl>, analysis_time_point <chr>,
#> #   analysis_full_contribution <lgl>, analysis_min_cell_count <dbl>,
#> #   denominator_cohort_id <int>, denominator_cohort_name <chr>,
#> #   denominator_age_group <chr>, denominator_sex <chr>, …

In addition, if we set returnParticipants as TRUE as above, we can identify the individuals who contributed to the prevalence rate analysis by using `participants(). For example, we can identify those people contributing to analysis 1 by running

participants(prev, analysisId = 1) %>%
  glimpse()
#> Rows: ??
#> Columns: 4
#> Database: DuckDB v0.9.2 [eburn@Windows 10 x64:R 4.2.1/:memory:]
#> $ subject_id         <chr> "8", "12", "19", "39", "45", "55", "65", "71", "101…
#> $ cohort_start_date  <date> 2008-01-01, 2008-01-01, 2008-01-01, 2008-01-01, 20…
#> $ cohort_end_date    <date> 2012-01-01, 2012-01-01, 2012-01-01, 2012-01-01, 20…
#> $ outcome_start_date <date> 1995-01-27, 1986-10-25, 2028-02-15, 1991-02-20, 20…

As we´ve used permanent tables for this example, we can drop these after running our analysis (note, the table created will start with write_prefix specified when creating the cdm reference).

# drop tables created when instantiating denominator cohorts
CDMConnector::dropTable(
  cdm = cdm,
  name = dplyr::starts_with("denominator")
)
# drop table with study participants when returnParticipants = TRUE
CDMConnector::dropTable(
  cdm = cdm,
  name = "period_prev_participants_1"
)
CDMConnector::cdm_disconnect(cdm)