Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: IncidencePrevalence
Title: Estimate Incidence and Prevalence using the OMOP Common Data Model
Version: 1.2.1
Version: 1.2.2
Authors@R: c(
person("Edward", "Burn", email = "edward.burn@ndorms.ox.ac.uk",
role = c("aut", "cre"),
Expand All @@ -25,7 +25,7 @@ Authors@R: c(
Description: Calculate incidence and prevalence using data mapped to the Observational Medical Outcomes Partnership (OMOP) common data model. Incidence and prevalence can be estimated for the total population in a database or for a stratification cohort.
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
RoxygenNote: 7.3.3
Depends:
R (>= 4.1)
Imports:
Expand Down
Binary file added GCSMiddleware-3.0.0.24.pkg
Binary file not shown.
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@
export("%>%")
export(asIncidenceResult)
export(asPrevalenceResult)
export(asRollingIncidenceResult)
export(attrition)
export(availableIncidenceGrouping)
export(availablePrevalenceGrouping)
export(availableRollingIncidenceGrouping)
export(benchmarkIncidencePrevalence)
export(bind)
export(cohortCodelist)
export(cohortCount)
export(estimateIncidence)
export(estimatePeriodPrevalence)
export(estimatePointPrevalence)
export(estimateRollingIncidence)
export(exportSummarisedResult)
export(generateDenominatorCohortSet)
export(generateTargetDenominatorCohortSet)
Expand All @@ -24,6 +27,7 @@ export(plotIncidence)
export(plotIncidencePopulation)
export(plotPrevalence)
export(plotPrevalencePopulation)
export(plotRollingIncidence)
export(settings)
export(suppress)
export(tableIncidence)
Expand Down
35 changes: 23 additions & 12 deletions R/estimateIncidence.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
#' stratify estimates.
#' @param includeOverallStrata Whether to include an overall result as well as
#' strata specific results (when strata has been specified).
#' @param rateDenominator The denominator to use for the incidence rate
#' calculation. Default is 100000.
#'
#' @return Incidence estimates
#' @export
Expand Down Expand Up @@ -87,7 +89,8 @@ estimateIncidence <- function(cdm,
outcomeWashout = Inf,
repeatedEvents = FALSE,
strata = list(),
includeOverallStrata = TRUE) {
includeOverallStrata = TRUE,
rateDenominator = 100000) {
startCollect <- Sys.time()

tablePrefix <- paste0(
Expand All @@ -98,6 +101,7 @@ estimateIncidence <- function(cdm,
if (is.character(interval)) {
interval <- tolower(interval)
}
rateDenominator <- as.integer(rateDenominator)

cohortIds <- checkInputEstimateIncidence(
cdm, denominatorTable, outcomeTable, censorTable,
Expand Down Expand Up @@ -291,7 +295,8 @@ estimateIncidence <- function(cdm,
tablePrefix = tablePrefix,
analysisId = x$analysis_id,
strata = strata,
includeOverallStrata = includeOverallStrata
includeOverallStrata = includeOverallStrata,
rateDenominator = rateDenominator
)

workingIncIr <- workingInc[["ir"]] %>%
Expand Down Expand Up @@ -374,7 +379,7 @@ estimateIncidence <- function(cdm,
if (nrow(irs) > 0) {
irs <- irs %>%
dplyr::bind_cols(
incRateCiExact(irs$outcome_count, irs$person_years)
incRateCiExact(irs$outcome_count, irs$person_years, rateDenominator)
)
}

Expand Down Expand Up @@ -437,8 +442,9 @@ estimateIncidence <- function(cdm,
tidyr::pivot_longer(
cols = c(
"denominator_count", "outcome_count", "person_days", "person_years",
"incidence_100000_pys", "incidence_100000_pys_95CI_lower",
"incidence_100000_pys_95CI_upper"
paste0("incidence_", rateDenominator, "_pys"),
paste0("incidence_", rateDenominator, "_pys_95CI_lower"),
paste0("incidence_", rateDenominator, "_pys_95CI_upper")
),
names_to = "estimate_name",
values_to = "estimate_value"
Expand Down Expand Up @@ -503,15 +509,20 @@ estimateIncidence <- function(cdm,



incRateCiExact <- function(ev, pt) {
incRateCiExact <- function(ev, pt, rateDenominator) {
rateDenominator <- as.integer(rateDenominator)
return(dplyr::tibble(
incidence_100000_pys_95CI_lower =
((stats::qchisq(p = 0.025, df = 2 * ev) / 2) / pt) * 100000,
incidence_100000_pys_95CI_upper =
((stats::qchisq(p = 0.975, df = 2 * (ev + 1)) / 2) / pt) * 100000
lower =
((stats::qchisq(p = 0.025, df = 2 * ev) / 2) / pt) * rateDenominator,
upper =
((stats::qchisq(p = 0.975, df = 2 * (ev + 1)) / 2) / pt) * rateDenominator
) |>
dplyr::mutate(incidence_100000_pys_95CI_lower = round(.data$incidence_100000_pys_95CI_lower, 3),
incidence_100000_pys_95CI_upper = round(.data$incidence_100000_pys_95CI_upper, 3))
dplyr::mutate(lower = round(.data$lower, 3),
upper = round(.data$upper, 3)) |>
dplyr::rename(
!!paste0("incidence_", rateDenominator, "_pys_95CI_lower") := "lower",
!!paste0("incidence_", rateDenominator, "_pys_95CI_upper") := "upper"
)
)
}

Expand Down
Loading