From 8df3a635761f6f637e2ced10f743538a4288a18d Mon Sep 17 00:00:00 2001 From: Hans-Martin von Gaudecker Date: Thu, 19 Nov 2026 18:18:43 +0100 Subject: [PATCH] Name the medical-cost shock states for the lag they hold The persistent and transitory states hold the previous period's shocks, so they are `lagged_hcc_persistent` and `lagged_hcc_transitory`. This period's costs read the transition's draws, `next_lagged_hcc_persistent` and `next_lagged_hcc_transitory`. The shock processes keep their names. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Hs8mfXPYyEa24KaAp6BwCW --- src/aca_model/baseline/health_insurance.py | 14 +++++++------- src/aca_model/baseline/regimes/_common.py | 4 ++-- src/aca_model/benchmark.py | 12 ++++++------ src/aca_model/config.py | 2 +- tests/test_benchmark_folding.py | 4 ++-- tests/test_budget_rules.py | 4 ++-- tests/test_dag_coverage.py | 4 ++-- tests/test_health_insurance.py | 4 ++-- tests/test_medical_cost_timing.py | 8 ++++---- tests/test_model_creation.py | 10 +++++----- tests/test_private_premium.py | 2 +- tests/test_transition_only_medical_shock.py | 6 +++--- 12 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/aca_model/baseline/health_insurance.py b/src/aca_model/baseline/health_insurance.py index ad76030..3c4d696 100644 --- a/src/aca_model/baseline/health_insurance.py +++ b/src/aca_model/baseline/health_insurance.py @@ -507,20 +507,20 @@ def hcc_insurer_predicted( period: Period, is_married: IntND, good_health: IntND, - hcc_persistent: ContinuousState, + lagged_hcc_persistent: ContinuousState, predicted_hcc_insurer_table: FloatND, hcc_persistent_grid: FloatND, ) -> FloatND: """Interpolate the private insurer's expected cost for the household. - `hcc_persistent` is last period's persistent shock, so the table holds + `lagged_hcc_persistent` is last period's persistent shock, so the table holds this period's E[total_costs - oop_costs | age, married, good health, lagged persistent node] on `[period, is_married, good_health, node]`. Linear interpolation handles off-grid values during simulation (where draw_shock returns continuous AR1 values). """ return jnp.interp( - hcc_persistent, + lagged_hcc_persistent, hcc_persistent_grid, predicted_hcc_insurer_table[period, is_married, good_health], ) @@ -573,15 +573,15 @@ def total_costs( good_health: IntND, log_mean: FloatND, log_std: FloatND, - next_hcc_persistent: ContinuousState, - next_hcc_transitory: ContinuousState, + next_lagged_hcc_persistent: ContinuousState, + next_lagged_hcc_transitory: ContinuousState, std_xsect_persistent: ScalarFloat, ) -> FloatND: """Compute this period's total health care costs from the log-normal model. Costs are realised after the period's choices. The persistent and transitory shocks that drive them are the draws the transition makes, - `next_hcc_persistent` and `next_hcc_transitory`: the next period carries + `next_lagged_hcc_persistent` and `next_lagged_hcc_transitory`: the next period carries them as its lagged shocks. Age, marital status and health are this period's. @@ -592,7 +592,7 @@ def total_costs( return jnp.exp( log_mean[period, is_married, good_health] + log_std[period, is_married, good_health] - * (next_hcc_persistent * std_xsect_persistent + next_hcc_transitory * std_trans) + * (next_lagged_hcc_persistent * std_xsect_persistent + next_lagged_hcc_transitory * std_trans) ) diff --git a/src/aca_model/baseline/regimes/_common.py b/src/aca_model/baseline/regimes/_common.py index 40a5c6c..2553b21 100644 --- a/src/aca_model/baseline/regimes/_common.py +++ b/src/aca_model/baseline/regimes/_common.py @@ -997,8 +997,8 @@ def build_model_states(grids: Grids) -> dict: solve=pensions.wealth, simulate=grids.pension_wealth, ), - "hcc_persistent": grids.hcc_persistent, - "hcc_transitory": grids.hcc_transitory, + "lagged_hcc_persistent": grids.hcc_persistent, + "lagged_hcc_transitory": grids.hcc_transitory, "spousal_income": DiscreteGrid( SpousalIncome, ), diff --git a/src/aca_model/benchmark.py b/src/aca_model/benchmark.py index 4ef0e9c..a5bcf30 100644 --- a/src/aca_model/benchmark.py +++ b/src/aca_model/benchmark.py @@ -189,8 +189,8 @@ def get_benchmark_initial_conditions( aime_pts = np.asarray(grids["aime"].to_jax()) # ty: ignore[unresolved-attribute] assets_lo, assets_hi = float(assets_pts.min()), float(assets_pts.max()) aime_lo, aime_hi = float(aime_pts.min()), float(aime_pts.max()) - hcc_p_pts = np.asarray(grids["hcc_persistent"].to_jax()) # ty: ignore[unresolved-attribute] - hcc_t_grid = grids.get("hcc_transitory") + hcc_p_pts = np.asarray(grids["lagged_hcc_persistent"].to_jax()) # ty: ignore[unresolved-attribute] + hcc_t_grid = grids.get("lagged_hcc_transitory") # Preserve the random stream for shared states; the transitory shock is no state. hcc_t_pts = ( np.asarray(hcc_t_grid.to_jax()) # ty: ignore[unresolved-attribute] @@ -215,8 +215,8 @@ def get_benchmark_initial_conditions( # pension wealth; the synthetic benchmark draws a modest positive stock. "pension_wealth": jnp.asarray(rng.uniform(0.0, 200_000.0, n_subjects)), "health": jnp.asarray(rng.integers(0, 3, n_subjects).astype(np.int32)), - "hcc_persistent": jnp.asarray(rng.choice(hcc_p_pts, n_subjects)), - "hcc_transitory": jnp.asarray(rng.choice(hcc_t_pts, n_subjects)), + "lagged_hcc_persistent": jnp.asarray(rng.choice(hcc_p_pts, n_subjects)), + "lagged_hcc_transitory": jnp.asarray(rng.choice(hcc_t_pts, n_subjects)), "spousal_income": jnp.asarray(rng.integers(0, 3, n_subjects).astype(np.int32)), "pref_type": jnp.asarray( rng.integers(0, _N_BENCHMARK_PREF_TYPES, n_subjects).astype(np.int32) @@ -227,6 +227,6 @@ def get_benchmark_initial_conditions( # everyone starts as not-yet-claimed. "claimed_ss": jnp.zeros(n_subjects, dtype=jnp.int32), } - if "hcc_transitory" not in model.state_names(regime_name=ENTRY_REGIMES[0]): - initial.pop("hcc_transitory") + if "lagged_hcc_transitory" not in model.state_names(regime_name=ENTRY_REGIMES[0]): + initial.pop("lagged_hcc_transitory") return initial diff --git a/src/aca_model/config.py b/src/aca_model/config.py index a093ca5..6ca8358 100644 --- a/src/aca_model/config.py +++ b/src/aca_model/config.py @@ -43,7 +43,7 @@ class GridConfig: # out-of-pocket bill, so the solve averages each target's value over the # transitory shock once per period instead of at every source point. Needs # the brute-force asset law. The transitory shock is read only as its draw - # `next_hcc_transitory`, so pylcm integrates it out and no value carries its + # `next_lagged_hcc_transitory`, so pylcm integrates it out and no value carries its # axis, with or without this option. subtract_hcc_bill: bool = False # The post-decision savings grid is cubically clustered toward the borrowing diff --git a/tests/test_benchmark_folding.py b/tests/test_benchmark_folding.py index b538f05..695a03b 100644 --- a/tests/test_benchmark_folding.py +++ b/tests/test_benchmark_folding.py @@ -16,7 +16,7 @@ def test_benchmark_folds_the_transitory_medical_bill( } assert living assert all( - "hcc_transitory" not in model.state_names(regime_name=name) for name in living + "lagged_hcc_transitory" not in model.state_names(regime_name=name) for name in living ) for regime in living.values(): laws = regime.state_transitions["assets"] @@ -25,4 +25,4 @@ def test_benchmark_folds_the_transitory_medical_bill( isinstance(law, lcm.AdditiveShockTransition) for law in laws.values() ) initial = get_benchmark_initial_conditions(model=model, n_subjects=8, seed=42) - assert "hcc_transitory" not in initial + assert "lagged_hcc_transitory" not in initial diff --git a/tests/test_budget_rules.py b/tests/test_budget_rules.py index 7797ce0..76ba70a 100644 --- a/tests/test_budget_rules.py +++ b/tests/test_budget_rules.py @@ -336,8 +336,8 @@ def test_married_household_cannot_consume_below_its_own_floor( consumption_dollars=jnp.asarray(consumption), cash_on_hand=jnp.asarray(500.0), consumption_dollars_floor=jnp.asarray(MARRIED_FLOOR), - hcc_persistent=jnp.asarray(0.0), - hcc_transitory=jnp.asarray(0.0), + lagged_hcc_persistent=jnp.asarray(0.0), + lagged_hcc_transitory=jnp.asarray(0.0), ) ) for constraint in constraints.values() diff --git a/tests/test_dag_coverage.py b/tests/test_dag_coverage.py index 9eaa79d..5d509db 100644 --- a/tests/test_dag_coverage.py +++ b/tests/test_dag_coverage.py @@ -142,5 +142,5 @@ def test_medical_cost_draws_keep_living_states_without_choice_constraints(model) if name == "dead": assert set(regime.states) == {"assets", "pref_type"} else: - assert "hcc_persistent" in regime.states - assert "hcc_transitory" not in regime.states + assert "lagged_hcc_persistent" in regime.states + assert "lagged_hcc_transitory" not in regime.states diff --git a/tests/test_health_insurance.py b/tests/test_health_insurance.py index 15d379d..538e07f 100644 --- a/tests/test_health_insurance.py +++ b/tests/test_health_insurance.py @@ -110,7 +110,7 @@ def test_predicted_hcc_insurer_on_grid() -> None: period=jnp.int32(0), is_married=jnp.int32(0), good_health=jnp.int32(1), - hcc_persistent=jnp.array(0.0), + lagged_hcc_persistent=jnp.array(0.0), predicted_hcc_insurer_table=TABLE, hcc_persistent_grid=GRID, ) @@ -122,7 +122,7 @@ def test_predicted_hcc_insurer_off_grid() -> None: period=jnp.int32(0), is_married=jnp.int32(0), good_health=jnp.int32(1), - hcc_persistent=jnp.array(-0.5), + lagged_hcc_persistent=jnp.array(-0.5), predicted_hcc_insurer_table=TABLE, hcc_persistent_grid=GRID, ) diff --git a/tests/test_medical_cost_timing.py b/tests/test_medical_cost_timing.py index dcebb5b..78960ed 100644 --- a/tests/test_medical_cost_timing.py +++ b/tests/test_medical_cost_timing.py @@ -24,7 +24,7 @@ ) from aca_model.config import BENCHMARK_GRID_CONFIG -_SHOCKS = ("hcc_persistent",) +_SHOCKS = ("lagged_hcc_persistent",) # Period 0's choices look one year ahead, so ages 51-53 (two living periods and # the age at which everybody is dead) carry the whole timing question. _FINAL_AGE = 53 @@ -83,7 +83,7 @@ def test_no_regime_carries_a_lagged_transitory_shock( ) -> None: """Last year's transitory shock is read by nothing, so it is no state.""" assert not any( - "hcc_transitory" in benchmark_model.state_names(regime_name=name) + "lagged_hcc_transitory" in benchmark_model.state_names(regime_name=name) for name in benchmark_model.user_regimes ) @@ -92,6 +92,6 @@ def test_value_falls_with_lagged_persistent_shock( period_0_by_shock: dict[tuple[str, str], pd.Series], ) -> None: """A higher lagged persistent shock predicts higher costs and lowers value.""" - low = period_0_by_shock["hcc_persistent", "low"]["value"] - high = period_0_by_shock["hcc_persistent", "high"]["value"] + low = period_0_by_shock["lagged_hcc_persistent", "low"]["value"] + high = period_0_by_shock["lagged_hcc_persistent", "high"]["value"] assert high < low diff --git a/tests/test_model_creation.py b/tests/test_model_creation.py index 608db83..0c36636 100644 --- a/tests/test_model_creation.py +++ b/tests/test_model_creation.py @@ -150,7 +150,7 @@ def test_all_non_terminal_regimes_have_core_states() -> None: regime = build_regime(name) assert "health" in regime.states model_states = build_model_states(_GRIDS) - for state_name in ("spousal_income", "assets", "hcc_persistent", "hcc_transitory"): + for state_name in ("spousal_income", "assets", "lagged_hcc_persistent", "lagged_hcc_transitory"): assert state_name in model_states @@ -279,11 +279,11 @@ def test_per_target_health_transitions() -> None: def test_hcc_persistent_and_transitory_are_shock_grids() -> None: - """hcc_persistent and hcc_transitory are ShockGrids with intrinsic transitions.""" + """lagged_hcc_persistent and lagged_hcc_transitory are ShockGrids with intrinsic transitions.""" for name in REGIME_SPECS: regime = build_regime(name) - assert "hcc_persistent" not in regime.state_transitions - assert "hcc_transitory" not in regime.state_transitions + assert "lagged_hcc_persistent" not in regime.state_transitions + assert "lagged_hcc_transitory" not in regime.state_transitions def test_aca_model_creates_successfully( @@ -417,7 +417,7 @@ def test_dead_regime_prunes_unused_broadcast_states(baseline_model: Model) -> No regimes); the other unused broadcast states are pruned by reachability.""" model = baseline_model assert model.pruned_variables["dead"] == frozenset( - {"aime", "spousal_income", "hcc_persistent", "hcc_transitory"} + {"aime", "spousal_income", "lagged_hcc_persistent", "lagged_hcc_transitory"} ) diff --git a/tests/test_private_premium.py b/tests/test_private_premium.py index 37d2932..c1f35b6 100644 --- a/tests/test_private_premium.py +++ b/tests/test_private_premium.py @@ -150,7 +150,7 @@ def test_predicted_hcc_insurer_reads_age_marriage_health_cell() -> None: period=jnp.int32(1), is_married=jnp.int32(1), good_health=jnp.int32(0), - hcc_persistent=jnp.asarray(0.5), + lagged_hcc_persistent=jnp.asarray(0.5), predicted_hcc_insurer_table=table, hcc_persistent_grid=jnp.array([-1.0, 0.0, 1.0]), ) diff --git a/tests/test_transition_only_medical_shock.py b/tests/test_transition_only_medical_shock.py index e007f98..bbfcd7e 100644 --- a/tests/test_transition_only_medical_shock.py +++ b/tests/test_transition_only_medical_shock.py @@ -2,7 +2,7 @@ Nothing a period computes reads last year's transitory shock: this year's draw enters the out-of-pocket bill inside the end-of-period asset law as -`next_hcc_transitory`, and the draw is IID. pylcm therefore draws it on the +`next_lagged_hcc_transitory`, and the draw is IID. pylcm therefore draws it on the transition only and integrates it in the continuation. Living regimes keep the lagged persistent shock, which prices the private premium. """ @@ -18,14 +18,14 @@ def model(baseline_model: Model) -> Model: def test_living_regimes_carry_no_lagged_transitory_shock(model: Model) -> None: assert not any( - "hcc_transitory" in model.state_names(regime_name=name) + "lagged_hcc_transitory" in model.state_names(regime_name=name) for name in model.user_regimes ) def test_living_regimes_keep_the_lagged_persistent_shock(model: Model) -> None: assert all( - "hcc_persistent" in model.state_names(regime_name=name) + "lagged_hcc_persistent" in model.state_names(regime_name=name) for name in model.user_regimes if name != "dead" )