Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/aca_model/baseline/health_insurance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
)
Expand Down Expand Up @@ -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.

Expand All @@ -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)
)


Expand Down
4 changes: 2 additions & 2 deletions src/aca_model/baseline/regimes/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
Expand Down
12 changes: 6 additions & 6 deletions src/aca_model/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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)
Expand All @@ -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
2 changes: 1 addition & 1 deletion src/aca_model/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/test_benchmark_folding.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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
4 changes: 2 additions & 2 deletions tests/test_budget_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions tests/test_dag_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions tests/test_health_insurance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -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,
)
Expand Down
8 changes: 4 additions & 4 deletions tests/test_medical_cost_timing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)

Expand All @@ -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
10 changes: 5 additions & 5 deletions tests/test_model_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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"}
)


Expand Down
2 changes: 1 addition & 1 deletion tests/test_private_premium.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_transition_only_medical_shock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand All @@ -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"
)