Skip to content

Commit

Permalink
Making rare outcome diagnostic more consistent with other diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
schuemie committed Nov 5, 2024
1 parent c960fc7 commit a7a805e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ S3method(confint,SccsModel)
S3method(print,SccsModel)
S3method(print,summary.SccsData)
S3method(print,summary.SccsIntervalData)
export(checkRareOutcomeAssumption)
export(computeEventDependentObservation)
export(computeExposureChange)
export(computeExposureStability)
Expand Down Expand Up @@ -47,7 +48,6 @@ export(getResultsSummary)
export(hasAgeEffect)
export(hasCalendarTimeEffect)
export(hasSeasonality)
export(isRareOutcomeAssumptionViolated)
export(isSccsData)
export(isSccsIntervalData)
export(loadExposuresOutcomeList)
Expand Down
20 changes: 12 additions & 8 deletions R/Diagnostics.R
Original file line number Diff line number Diff line change
Expand Up @@ -744,14 +744,15 @@ computeExposureStability <- function(studyPopulation,
#' Modelling Guide with R, CRC Press, 2018
#'
#' @return
#' A logical value, which is TRUE if the rare outcome assumption is violated. The assumption is
#' violated when restricting to first outcome only and the prevalence exceeds the pre-defined
#' threshold.
#' A tibble with one row and three columns: `outcomeProportion` indicates the proportion of people
#' having the outcome at least once. `firstOutcomeOnly` indicated whether the analysis was restricted
#' to the first outcome only. `rare` is TRUE if the rare outcome assumption is met, or the analysis
#' was not restricted to the first outcome.
#'
#' @export
isRareOutcomeAssumptionViolated <- function(studyPopulation,
firstOutcomeOnly = NULL,
maxPrevalence = 0.1) {
checkRareOutcomeAssumption <- function(studyPopulation,
firstOutcomeOnly = NULL,
maxPrevalence = 0.1) {
errorMessages <- checkmate::makeAssertCollection()
checkmate::assertList(studyPopulation, min.len = 1, add = errorMessages)
checkmate::assertLogical(firstOutcomeOnly, len = 1, null.ok = TRUE, add = errorMessages)
Expand All @@ -762,8 +763,11 @@ isRareOutcomeAssumptionViolated <- function(studyPopulation,
firstOutcomeOnly <- prevalence$definitelyFirstOutcomeOnly | prevalence$probablyFirstOutcomeOnly
}
if (firstOutcomeOnly) {
return(prevalence$outcomeProportion > maxPrevalence)
rare <- prevalence$outcomeProportion <= maxPrevalence
} else {
return(FALSE)
rare <- TRUE
}
return(tibble(outcomeProportion = prevalence$outcomeProportion,
firstOutcomeOnly = firstOutcomeOnly,
rare = rare))
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a7a805e

Please sign in to comment.