View source: R/progression-ratios.R
| progression_ratios | R Documentation |
Calculates cohort survival / grade progression ratios from historical grade-level enrollment. For each non-entry grade, the ratio is enrollment in that grade divided by enrollment in the grade below one year earlier, summarised across the available year-to-year transitions.
progression_ratios(
data,
year = "year",
grade = "grade",
enrollment = "enrollment",
method = c("mean", "geometric", "median", "last", "weighted"),
n_years = NULL,
weights = NULL,
grade_order = NULL
)
data |
A long data frame or data-frame subclass of historical enrollment
with one row per grade per year. Enrollment may be |
year, grade, enrollment |
Distinct, non-missing character scalars naming
columns in |
method |
How to summarise per-year ratios into one ratio per grade:
|
n_years |
Optional. Use only the most recent |
weights |
For |
grade_order |
Optional character vector giving the low-to-high grade order. If omitted, factor levels, numeric ordering, or (with a warning) alphabetical ordering is used. |
Only transitions between observed consecutive calendar years are used. If
the history has one or more calendar-year gaps but still contains an adjacent
year pair, the gaps are reported in a warning and are not bridged. Histories
with no adjacent year pair are rejected. Gap detection examines the complete
supplied history before n_years selects recent adjacent transitions, so an
older gap still warns even when it lies outside the selected transitions.
A data frame with columns grade_from, grade_to, and ratio,
one row per non-entry grade.
history <- data.frame(
year = rep(2021:2023, each = 3),
grade = factor(rep(c("K", "1", "2"), 3), levels = c("K", "1", "2")),
enrollment = c(100, 90, 80, 110, 95, 88, 120, 99, 91)
)
progression_ratios(history)
# For method = "weighted", weights align most-recent to oldest: here the
# 2022->2023 transition gets weight 2 and 2021->2022 gets weight 1.
progression_ratios(history, method = "weighted", weights = c(2, 1))
# The same K -> 1 ratio via stats::weighted.mean(). Unlike `weights`
# above, weighted.mean() pairs each weight with the value at the same
# position, and the per-year ratios run oldest to newest -- so the
# weights must be reversed to line up.
k_ratios <- c(95 / 100, 99 / 110) # 2021->2022, then 2022->2023
stats::weighted.mean(k_ratios, rev(c(2, 1)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.