H23 Calculate the rate locally
Use your current course session. Preparation and course runner · R script ↓
H23 Calculate the rate locally
Goal: Reproduce the hand calculation.
Prerequisites: H22.
A successful in-memory run supports exploratory measurement, but not an approved frozen report.
training_step(
"H23",
{
local_rate <- dataraft.metrics::dr_measure(
cohort_run,
cancellation_metric,
by = character()
)
print(local_rate)
stopifnot(isTRUE(all.equal(local_rate$value, 1 / 6)))
},
needs = c("H22")
)Expected result: A ratio of 0.1666667, or about 16.67 percent.
Task: Why not multiply by 100 in the definition?
Show solution
Keeping unit ratio makes the meaning explicit; percentage formatting can be separate.
H23a Handle an empty opening population
Goal: Prevent a rate without a valid denominator.
Prerequisites: H21; do not collect a metric from a blocked run.
A population with no eligible policies cannot support this rate. Run the counterexample, then return to cohort_run.
training_step(
"H23a",
{
no_opening_data <- dated_policies
no_opening_data$start_date <- as.Date("2026-08-10")
no_opening_run <- dr_run(
cohort_product,
data = no_opening_data,
write = FALSE,
stop_on_failure = FALSE
)
print(dr_quality_report(no_opening_run))
stopifnot(no_opening_run$status == "blocked")
},
needs = c("H21")
)Expected result: nonempty_denominator blocks output.
Task: Why would zero be misleading?
Show solution
It would suggest an observed population with no cancellations. Here the opening population is absent.