
Detect structural regime shifts across underwriting cohorts
Source:R/regime.R
detect_cohort_regime.RdDetect structural change points in the sequence of cohort-level
development trajectories. Each underwriting cohort (indexed by the
cohort_var of a "Triangle" object) is treated as a feature vector
whose entries are the selected value_var observed at development
periods 1, ..., K. Cohorts are then ordered by underwriting
period and tested for structural shifts in the multivariate
sequence.
Three detection strategies are supported:
"ecp"Multivariate non-parametric divisive change-point detection via
ecp::e.divisive(). The number of regimes is determined by the data; only significant breakpoints atsig_levelare retained. Preferred when the number of regimes is not known in advance."pelt"Univariate mean change-point detection via
changepoint::cpt.mean()with the PELT algorithm applied to the first principal component of the cohort feature matrix. Fast and may return multiple breakpoints."hclust"Ward hierarchical clustering on the scaled cohort feature matrix, cut to
n_regimesclusters. Ignores time ordering — useful as a sanity check since non-adjacent cohorts may cluster together if the trajectory pattern is not strictly chronological.
Usage
detect_cohort_regime(
x,
value_var = "clr",
K = 12L,
method = c("ecp", "pelt", "hclust"),
n_regimes = NULL,
sig_level = 0.05,
min_size = 3L,
...
)
# S3 method for class 'CohortRegime'
print(x, ...)
# S3 method for class 'CohortRegime'
summary(object, ...)
# S3 method for class 'summary.CohortRegime'
print(x, ...)Arguments
- x
An object of class
"Triangle". Must correspond to a single group (nogroup_varor a single-valuegroup_varsubset). Also used by S3print()method onCohortRegimeobjects.- value_var
Column name of the trajectory variable. Default is
"clr"(cumulative loss ratio).- K
Integer. Common development-period window used to build the cohort feature matrix. Cohorts with fewer than
Kobserved periods are dropped. Default is12.- method
One of
"ecp","pelt","hclust".- n_regimes
Integer. Number of regimes to force.
NULLmeans auto-detect for"ecp"and"pelt"; ignored (required to equal the requested value) for"hclust", where the default is2.- sig_level
Significance level for
"ecp". Default0.05.- min_size
Minimum segment size for
"ecp". Default3.- ...
Reserved for future use.
- object
An object of class
"CohortRegime". Used by the S3summary()method.
Value
An object of class "CohortRegime" with components:
callMatched call.
methodDetection method used.
value_var,KTrajectory variable and window.
cohort_varPeriod variable from
x.labelsdata.tablewith one row per analysed cohort: period, regime id, regime label.breakpointsDatevector of breakpoint dates (each is the first cohort of a new regime; excludes the initial regime start).n_regimesNumber of regimes detected.
trajectoryCohort feature matrix (rows = cohorts, columns = development periods
1, ..., K).pcaprcompobject fitted to the feature matrix.droppedCohorts excluded due to the
Kwindow constraint.
Examples
if (FALSE) { # \dontrun{
data(experience)
exp <- as_experience(experience)
tri_sur <- build_triangle(exp[cv_nm == "SUR"], group_var = cv_nm)
# Hierarchical clustering (no extra package dependency)
r <- detect_cohort_regime(tri_sur, K = 12, method = "hclust",
n_regimes = 2L)
print(r)
summary(r)
plot(r)
# ecp divisive change-point detection (requires the ecp package)
r_ecp <- detect_cohort_regime(tri_sur, K = 12, method = "ecp")
} # }