replay_history#

causalpy.historical_validation.replay_history(history, treated_unit, control_units, schedule, decision, *, model=None, random_seed=None, sample_kwargs=None, donor_correlation=None, auto_scale_sigma=True, fit_audit=False, fit_learned_null=True, rope_half_width=0.0, threshold=0.95, time_column=None)[source]#

Replay a validated schedule on its history and build a calibration record.

Parameters:
  • history (DataFrame) – The same history the schedule was built from, or a copy. A frame that no longer contains the scheduled labels is rejected. The caller’s frame is not mutated.

  • treated_unit (str) – Must match the schedule.

  • control_units (Sequence[str]) – Must match the schedule.

  • schedule (HistoricalSchedule) – Output of validate_schedule().

  • decision (DecisionRule) – One-sided rule used only to set detected. Bias columns are filled either way.

  • model (WeightedSumFitter | None) – Unfitted template. Each window receives a clone. When omitted, sample_kwargs must include draws so replay does not fall back to a 1000-draw, 4-chain default.

  • random_seed (int | None) – Seed copied onto every clone. An explicit sample_kwargs seed overrides it, matching the planner.

  • sample_kwargs (dict[str, Any] | None) – Merged onto each clone. Must include draws when model is omitted.

  • donor_correlation (float | None) – Passed to synthetic control as min_donor_correlation. The default is the estimator default, 0.

  • auto_scale_sigma (bool) – Passed through to synthetic control. Default true.

  • fit_audit (bool) – Default false. Audit windows stay reserved and out of the null model. True fits them and means they are no longer untouched; their scores still do not enter calibration.

  • fit_learned_null (bool) – Default true. The null model runs only when at least two selection windows scored, no usable selection window failed or was refused, their diagnostics are available, no scored selection window has a positive divergence count, and their posterior standard deviations are positive. High R-hat and low ESS are kept on the window and are not given a cutoff here. Otherwise the record stays inapplicable and names the reason.

  • rope_half_width (float) – Stored on the calibration record for the operating-characteristics engine. Default 0. This is not the decision rule’s effect threshold.

  • threshold (float) – Decision probability stored for the engine. Default 0.95. This is not causalpy.design.DecisionRule.threshold.

  • time_column (str | None) – Time column, when the history is not already indexed by time.

Returns:

Per-window scores, bias, and a calibration record. No CheckResult is constructed.

Return type:

HistoricalReplay

Raises:
  • TypeError – If the schedule, decision, model, or seed has the wrong type.

  • ValueError – If the history or units do not match the schedule, or if sampling settings would silently use the heavy model default.

  • DataException – If the history index is missing, duplicated, or not sorted. A boundary check failure, including an exception other than RuntimeError, is recorded on that window as not-run; it does not abort the remaining windows.