User-facing helper for hand-specifying a regime change (or a set of
per-group changes) without running detect_regime(). The returned
"Regime" object plugs into any function that consumes a Regime –
fit_ratio(), fit_loss(), fit_premium(), backtest(), and the
regime-change resolver – by carrying the same $changes schema as
detect_regime() output.
Argument syntax mirrors data.frame() / data.table(): named
vectors of equal length, one of which must be change. Any
other named arguments are treated as group columns.
Usage
regime_at(..., treatment = c("segment_bridged", "segment_bridged_borrowed"))Arguments
- ...
Named vectors of equal length. Must include
change(coercible toDate; the start-of-regime date for the post-change regime). Any other named arguments are interpreted as group column values (e.g.coverage,channel). With no group columns the result is a pooled (single-row) Regime.- treatment
How downstream fits should apply this Regime when
$changescontains multiple change points."segment_bridged"(default) pools the bridged development band into a single factor estimate."segment_bridged_borrowed"estimates per-segment factors and borrows the late-dev factors a segment cannot reach. Both mask to the bridged band so every cohort projects to full development. Seedetect_regime()for full semantics.
Value
An object of class "Regime" with the minimal schema needed
by downstream consumers:
method"manual".lossNA_character_(no detection metric).changesdata.tablewith columns[<group cols>..., change, regime_id, pre_value, post_value, magnitude].regime_idis2L(post-change regime) for each row; the stats columns areNA_real_.groupsCharacter vector of group column names (possibly empty).
multi_groupTRUEwhen there are group columns and more than one unique group row.
Detection-specific slots (labels, trajectory, pca, dropped,
n_regimes, window, window_mode, pca) are left empty / NA
so the object can still be printed and consumed but is clearly
distinguishable from a detected Regime.
Examples
if (FALSE) { # \dontrun{
# Pooled change (no group columns)
regime_at(change = "2024-07-01")
# Single-group change
regime_at(coverage = "surgery", change = "2024-04-01")
# Multiple groups, one column
regime_at(coverage = c("surgery", "cancer"),
change = c("2024-04-01", "2023-09-01"))
# Multi-dimensional group keys
regime_at(coverage = c("surgery", "surgery"),
channel = c("online", "agent"),
change = c("2024-04-01", "2024-05-01"))
} # }
