CohortPrevalenceExperiment.RdDefine and manage multi-dimensional prevalence analysis experiments. Enables users to specify cohorts, prevalence types, demographic constraints, and periods of interest, then automatically generates a Cartesian product of analysis definitions with full provenance tracking.
The experiment class uses the builder pattern to define analysis dimensions:
Add cohorts (one or more)
Add prevalence types (one or more)
Add demographic constraints (one or more)
Add periods of interest (one or more)
Set common parameters (strata, output types)
Call define() to materialize analysis objects
Pass analysis list to generatePrevalence()
Input: Object-based (type-safe), validated on each addition
Output: Flat tibble specification, CSV-exportable for reproducibility
Execution: exp$define() → generatePrevalence(analyses, ...)
Explicit data flow: experiment defines dimensions, define() materializes analyses, generatePrevalence() executes
exp <- CohortPrevalenceExperiment$new("CKD Multi-Cohort")
exp$addCohorts(tibble::tibble(
cohortId = c(1, 2, 3),
cohortName = c("CKD A", "CKD B", "CKD C")
))
exp$addPrevalenceTypes(list(
createPrevalenceType("point", lookBackDays = 0L),
createPrevalenceType("period_prevalence_pd2", lookBackDays = 365L),
createPrevalenceType("period_prevalence_pd3", lookBackDays = 0L)
))
exp$addDemographicConstraints(list(
createDemographicConstraints(ageMin = 18, ageMax = 150, genderIds = c(8507L, 8532L, 0L)),
createDemographicConstraints(ageMin = 65, ageMax = 150, genderIds = c(8507L, 8532L, 0L)),
createDemographicConstraints(ageMin = 18, ageMax = 150, genderIds = c(8507L))
))
exp$addPeriodsOfInterest(list(
createYearlyRange(2015:2024),
createSpan(start = "2020-01-01", end = "2020-12-31"),
createSpan(start = "2021-01-01", end = "2021-12-31")
))
exp$setCommonParameters(strata = c("age", "gender"), outputTypes = "prevalence")
# View specification
exp$viewDesign()
exp$viewDesign("html")
# Define analyses (3 × 3 × 3 × 3 = 81 analyses)
analyses <- exp$define()
# Execute
results <- generatePrevalence(analyses, executionSettings = settings)addCohorts()Add cohort definitions
addDemographicConstraints()Add demographic constraint definitions
setCommonParameters()Set common parameters for all analyses
CohortPrevalenceExperiment$setCommonParameters(
strata = NULL,
outputTypes = NULL,
minimumObservationLength = 0L,
useOnlyFirstObservationPeriod = FALSE
)strataCharacter vector of strata variables (e.g., c("age", "gender"))
outputTypesCharacter vector of output types (e.g., "prevalence")
minimumObservationLengthInteger minimum lead-in days before each POI start date
useOnlyFirstObservationPeriodLogical. If TRUE, only first observation period per person is used