diff --git a/changelog.d/medicaid-non-filer-household-once.fixed.md b/changelog.d/medicaid-non-filer-household-once.fixed.md new file mode 100644 index 00000000000..d938af68e0d --- /dev/null +++ b/changelog.d/medicaid-non-filer-household-once.fixed.md @@ -0,0 +1 @@ +Count overlapping applicant, spouse, parent and child-age members once in Medicaid non-filer household size and income when explicit parent links are absent. diff --git a/policyengine_us/tests/policy/baseline/gov/hhs/medicaid/eligibility/categories/is_adult_for_medicaid.yaml b/policyengine_us/tests/policy/baseline/gov/hhs/medicaid/eligibility/categories/is_adult_for_medicaid.yaml index a7f6e4177f2..9bb9ab294ce 100644 --- a/policyengine_us/tests/policy/baseline/gov/hhs/medicaid/eligibility/categories/is_adult_for_medicaid.yaml +++ b/policyengine_us/tests/policy/baseline/gov/hhs/medicaid/eligibility/categories/is_adult_for_medicaid.yaml @@ -328,3 +328,31 @@ state_code: MO output: is_adult_for_medicaid_fc: [false, false, false, false] + +# A Household API partner reported this household (issue 9562): a New Jersey +# parent and an 18-year-old child with no relationship or tax-role inputs. The +# model builds the omitted marital units, so the 18-year-old is the parent's +# dependent, and the parent files. +- name: New Jersey parent of an 18-year-old with no role inputs is above the adult group limit + period: 2026 + absolute_error_margin: 0.001 + input: + people: + person1: + age: 45 + employment_income: 31_000 + person2: + age: 18 + households: + household: + members: [person1, person2] + state_code: NJ + output: + # Household of 2 (medicaid_household_size Case 12). 2026 guideline for 2: + # 15,960 + 5,680 = 21,640, and 31,000 / 21,640 = 1.4325. The 138% limit is + # 21,640 x 1.38 / 12 = 2,488.60, rounded up to 2,489 a month, a 1.3802 + # ratio. Before those units were built, the model took the 18-year-old as + # the spouse and counted them twice: 3, and 31,000 / 27,320 = 1.1347, + # inside the limit. The 18-year-old is under the adult age range. + medicaid_income_level: [1.4325, 1.4325] + is_adult_for_medicaid: [false, false] diff --git a/policyengine_us/tests/policy/baseline/gov/hhs/medicaid/income/medicaid_household_income.yaml b/policyengine_us/tests/policy/baseline/gov/hhs/medicaid/income/medicaid_household_income.yaml index 50ac0ef050b..7a08e89b757 100644 --- a/policyengine_us/tests/policy/baseline/gov/hhs/medicaid/income/medicaid_household_income.yaml +++ b/policyengine_us/tests/policy/baseline/gov/hhs/medicaid/income/medicaid_household_income.yaml @@ -443,3 +443,284 @@ # parents ((f)(3)(iii)): 12,000 - 5,000 = 7,000 for all three. medicaid_uses_non_filer_rules: [true, true, true] medicaid_household_income: [7_000, 7_000, 7_000] + +# The next cases enter each member's MAGI-based income as an input, after the +# filing-threshold exclusions, to isolate who the non-filer household counts +# (42 CFR 435.603(f)(3)). Each member's amount enters once, as in +# medicaid_household_size. +- name: Non-filer membership counts each income once for an adult with an 18-year-old spouse. + period: 2025 + absolute_error_margin: 0.01 + input: + people: + parent1: + age: 35 + own_children_in_household: 1 + medicaid_household_income_member: 1_200 + medicaid_uses_non_filer_rules: true + parent2: + age: 18 + own_children_in_household: 1 + medicaid_household_income_member: 2_300 + medicaid_uses_non_filer_rules: true + child: + age: 1 + medicaid_household_income_member: 400 + medicaid_uses_non_filer_rules: true + marital_units: + couple: + members: [parent1, parent2] + child_unit: + members: [child] + households: + household: + members: [parent1, parent2, child] + state_code: CA + output: + # Each parent: self, spouse and child. The child: self and both parents. + # 1,200 + 2,300 + 400 = 3,900 for all three. + medicaid_household_income: [3_900, 3_900, 3_900] + +- name: Non-filer membership counts each income once for 18-year-old spouses filing separately. + period: 2025 + absolute_error_margin: 0.01 + input: + people: + parent1: + age: 18 + own_children_in_household: 1 + medicaid_household_income_member: 1_200 + medicaid_uses_non_filer_rules: true + parent2: + age: 18 + own_children_in_household: 1 + medicaid_household_income_member: 2_300 + medicaid_uses_non_filer_rules: true + child: + age: 1 + medicaid_household_income_member: 400 + medicaid_uses_non_filer_rules: true + marital_units: + couple: + members: [parent1, parent2] + child_unit: + members: [child] + tax_units: + return1: + members: [parent1, child] + cohabitating_spouses: true + return2: + members: [parent2] + cohabitating_spouses: true + households: + household: + members: [parent1, parent2, child] + state_code: CA + output: + # The cohabiting spouse on the other return is the spouse: 3,900 for all + # three. + medicaid_household_income: [3_900, 3_900, 3_900] + +- name: Non-filer membership counts each income once for 18-year-old parents netting a business loss. + period: 2025 + absolute_error_margin: 0.01 + input: + people: + parent1: + age: 18 + own_children_in_household: 1 + medicaid_household_income_member: 1_200 + medicaid_uses_non_filer_rules: true + parent2: + age: 18 + own_children_in_household: 1 + medicaid_household_income_member: -500 + medicaid_uses_non_filer_rules: true + child: + age: 1 + medicaid_household_income_member: 0 + medicaid_uses_non_filer_rules: true + marital_units: + couple: + members: [parent1, parent2] + child_unit: + members: [child] + households: + household: + members: [parent1, parent2, child] + state_code: CA + output: + # The spouse's loss is added signed: 1,200 - 500 = 700 for each parent. + # The child's married parents are netted before the floor: 700. + medicaid_household_income: [700, 700, 700] + +- name: Non-filer membership counts each income once for an 18-year-old in the spouse role on a head of household return. + period: 2026 + absolute_error_margin: 0.01 + input: + people: + parent: + age: 45 + own_children_in_household: 1 + is_tax_unit_head: true + medicaid_household_income_member: 1_200 + medicaid_uses_non_filer_rules: true + child: + age: 18 + is_tax_unit_spouse: true + medicaid_household_income_member: 400 + medicaid_uses_non_filer_rules: true + tax_units: + tax_unit: + members: [parent, child] + filing_status: HEAD_OF_HOUSEHOLD + households: + household: + members: [parent, child] + state_code: NJ + output: + # The 18-year-old is input as the tax unit spouse, but the return isn't + # joint, so neither is the other's spouse, as in medicaid_household_size. + # The parent's household has the 18-year-old as a child under 19, and the + # 18-year-old's has the parent: 1,200 + 400 = 1,600 for both. Main gave + # 2,000 and 2,800. + medicaid_household_income: [1_600, 1_600] + +- name: Non-filer membership counts each income once for married 18-year-old parents on separate returns without the cohabiting flag. + period: 2025 + absolute_error_margin: 0.01 + input: + people: + parent1: + age: 18 + own_children_in_household: 1 + medicaid_household_income_member: 1_200 + medicaid_uses_non_filer_rules: true + parent2: + age: 18 + own_children_in_household: 1 + medicaid_household_income_member: 2_300 + medicaid_uses_non_filer_rules: true + child: + age: 1 + medicaid_household_income_member: 400 + medicaid_uses_non_filer_rules: true + marital_units: + couple: + members: [parent1, parent2] + child_unit: + members: [child] + tax_units: + return1: + members: [parent1, child] + return2: + members: [parent2] + households: + household: + members: [parent1, parent2, child] + state_code: CA + output: + # Without a joint return or the cohabiting flag, neither parent is the + # other's identified spouse, so each is the other's relative parent. The + # applicant's own amount is netted out of the couple first: + # 1,200 + (3,500 - 1,200) + 400 = 3,900, and 2,300 + 1,200 + 400 = 3,900. + medicaid_household_size: [3, 3, 3] + medicaid_household_income: [3_900, 3_900, 3_900] + +- name: Non-filer membership nets each income once when the whole household is listed as one marital unit. + period: 2025 + absolute_error_margin: 0.01 + input: + people: + grandmother: + age: 45 + own_children_in_household: 1 + medicaid_household_income_member: 0 + medicaid_uses_non_filer_rules: false + parent1: + age: 18 + own_children_in_household: 1 + is_tax_unit_head: true + medicaid_household_income_member: 1_200 + medicaid_uses_non_filer_rules: true + parent2: + age: 18 + own_children_in_household: 1 + is_tax_unit_spouse: true + medicaid_household_income_member: 2_300 + medicaid_uses_non_filer_rules: true + child: + age: 1 + medicaid_household_income_member: 400 + medicaid_uses_non_filer_rules: true + marital_units: + household_unit: + members: [grandmother, parent1, parent2, child] + tax_units: + grandmother_unit: + members: [grandmother] + parents: + members: [parent1, parent2, child] + households: + household: + members: [grandmother, parent1, parent2, child] + state_code: CA + output: + # The joint-return spouse shares the listed marital unit with the + # grandmother, parent1's parent. A parent's netted share of that unit + # leaves out both the applicant and the spouse, so the grandmother adds + # her own 0: 1,200 + 2,300 + 0 + 400 = 3,900 for each parent. Parent2 and + # the child count her only through the family-level proxy (#9404). The + # child adds the unit's three parents netted together: 400 + 3,500 = + # 3,900. The grandmother's own household is her tax household, with no + # income. + medicaid_household_income: [0, 3_900, 3_900, 3_900] + +- name: Non-filer membership divides a listed marital unit's remaining parent income among the remaining parents only. + period: 2025 + absolute_error_margin: 0.01 + input: + people: + grandmother: + age: 45 + own_children_in_household: 1 + medicaid_household_income_member: 600 + medicaid_uses_non_filer_rules: false + parent1: + age: 18 + own_children_in_household: 1 + is_tax_unit_head: true + medicaid_household_income_member: 1_200 + medicaid_uses_non_filer_rules: true + parent2: + age: 18 + own_children_in_household: 1 + is_tax_unit_spouse: true + medicaid_household_income_member: 2_300 + medicaid_uses_non_filer_rules: true + child: + age: 1 + medicaid_household_income_member: 400 + medicaid_uses_non_filer_rules: true + marital_units: + household_unit: + members: [grandmother, parent1, parent2, child] + tax_units: + grandmother_unit: + members: [grandmother] + parents: + members: [parent1, parent2, child] + households: + household: + members: [grandmother, parent1, parent2, child] + state_code: CA + output: + # Only parent1 is asserted: the grandmother is parent1's parent + # (42 CFR 435.603(f)(3)(iii)), while parent2 and the child would count her + # only through the family-level proxy (#9404). Parent1's netted share of + # the unit leaves out parent1 and the spouse: + # (600 + 1,200 + 2,300 - 1,200 - 2,300) / (3 - 2) = 600, so + # 1,200 + 2,300 + 600 + 400 = 4,500. + people: + parent1: + medicaid_household_income: 4_500 diff --git a/policyengine_us/tests/policy/baseline/gov/hhs/medicaid/income/medicaid_household_size.yaml b/policyengine_us/tests/policy/baseline/gov/hhs/medicaid/income/medicaid_household_size.yaml index e0d8a81bef7..8487f6a9e9f 100644 --- a/policyengine_us/tests/policy/baseline/gov/hhs/medicaid/income/medicaid_household_size.yaml +++ b/policyengine_us/tests/policy/baseline/gov/hhs/medicaid/income/medicaid_household_size.yaml @@ -97,3 +97,330 @@ state_code: KS output: medicaid_household_size: 1 + +# 42 CFR 435.603(f)(3): a non-filer's household is the individual and, if +# living with them, their spouse, their children under 19 and, for an +# individual under 19, their parents and siblings under 19. Each person counts +# once, even when they fit more than one of those groups, such as a spouse who +# is also under 19 or a parent who is also under 19. Without parent ids the +# parents and children come from the family (is_parent and age). Cases 4-11 +# are the household examples in issue 9562. +- name: Case 4, non-filing adults and their child keep the ordinary household size. + period: 2025 + input: + people: + person1: + age: 35 + person2: + age: 35 + person3: + age: 1 + marital_units: + marital_unit: + members: [person1, person2] + marital_unit2: + members: [person3] + households: + household: + members: [person1, person2, person3] + state_code: CA + output: + tax_unit_size: 3 + tax_unit_is_filer: false + medicaid_uses_non_filer_rules: [true, true, false] + # Each adult: self, spouse and child. The child: the tax household of 3. + medicaid_household_size: [3, 3, 3] + +- name: Case 5, filing adults and their child keep the ordinary household size. + period: 2025 + input: + people: + person1: + age: 35 + employment_income: 50_000 + person2: + age: 35 + person3: + age: 1 + marital_units: + marital_unit: + members: [person1, person2] + marital_unit2: + members: [person3] + households: + household: + members: [person1, person2, person3] + state_code: CA + output: + tax_unit_size: 3 + tax_unit_is_filer: true + medicaid_uses_non_filer_rules: [false, false, false] + medicaid_household_size: [3, 3, 3] + +- name: Case 6, non-filing 18-year-old spouses without parent-count inputs are each counted once. + period: 2025 + input: + people: + person1: + age: 18 + person2: + age: 18 + person3: + age: 1 + marital_units: + marital_unit: + members: [person1, person2] + marital_unit2: + members: [person3] + households: + household: + members: [person1, person2, person3] + state_code: CA + output: + tax_unit_size: 3 + tax_unit_is_filer: false + medicaid_uses_non_filer_rules: [true, true, false] + # Each spouse: self, spouse and child. Main also counted the spouse as a + # family member under 19, giving 4. + medicaid_household_size: [3, 3, 3] + +- name: Case 7, filing 18-year-old spouses keep their tax household size. + period: 2025 + input: + people: + person1: + age: 18 + employment_income: 50_000 + person2: + age: 18 + person3: + age: 1 + marital_units: + marital_unit: + members: [person1, person2] + marital_unit2: + members: [person3] + households: + household: + members: [person1, person2, person3] + state_code: CA + output: + tax_unit_size: 3 + tax_unit_is_filer: true + medicaid_uses_non_filer_rules: [false, false, false] + medicaid_household_size: [3, 3, 3] + +- name: Case 8, non-filing 18-year-old parents and their child are each counted once. + period: 2025 + input: + people: + person1: + age: 18 + own_children_in_household: 1 + person2: + age: 18 + own_children_in_household: 1 + person3: + age: 1 + marital_units: + marital_unit: + members: [person1, person2] + marital_unit2: + members: [person3] + households: + household: + members: [person1, person2, person3] + state_code: CA + output: + tax_unit_size: 3 + tax_unit_is_filer: false + medicaid_uses_non_filer_rules: [true, true, false] + # Each parent: self, spouse and child. Main gave 6: the spouse, both + # parents and the three people under 19. + medicaid_household_size: [3, 3, 3] + +- name: Case 9, non-filing 18-year-old parents add an expected child after counting members once. + period: 2025 + input: + people: + person1: + age: 18 + own_children_in_household: 1 + person2: + age: 18 + own_children_in_household: 1 + current_pregnancies: 1 + person3: + age: 1 + marital_units: + marital_unit: + members: [person1, person2] + marital_unit2: + members: [person3] + households: + household: + members: [person1, person2, person3] + state_code: CA + output: + tax_unit_size: 3 + tax_unit_is_filer: false + medicaid_uses_non_filer_rules: [true, true, false] + # Case 8's 3 members plus the 1 expected child, which California counts in + # every member's household (ca_medicaid_household_pregnancies). + medicaid_household_size: [4, 4, 4] + +- name: Case 10, a non-filing adult and an 18-year-old spouse are each counted once. + period: 2025 + input: + people: + person1: + age: 35 + own_children_in_household: 1 + person2: + age: 18 + own_children_in_household: 1 + person3: + age: 1 + marital_units: + marital_unit: + members: [person1, person2] + marital_unit2: + members: [person3] + households: + household: + members: [person1, person2, person3] + state_code: CA + output: + tax_unit_size: 3 + tax_unit_is_filer: false + medicaid_uses_non_filer_rules: [true, true, false] + # Each parent: self, spouse and child. Main gave the adult 4 (the spouse + # again as a member under 19) and the 18-year-old 5. + medicaid_household_size: [3, 3, 3] + +- name: Case 11, non-filing 18-year-old spouses on separate tax returns are each counted once. + period: 2025 + input: + people: + person1: + age: 18 + own_children_in_household: 1 + person2: + age: 18 + own_children_in_household: 1 + person3: + age: 1 + marital_units: + marital_unit: + members: [person1, person2] + marital_unit2: + members: [person3] + tax_units: + tax_unit1: + members: [person1, person3] + cohabitating_spouses: true + tax_unit2: + members: [person2] + cohabitating_spouses: true + households: + household: + members: [person1, person2, person3] + state_code: CA + output: + tax_unit_is_filer: [false, false] + # The cohabiting spouse on the other return is the spouse (42 CFR + # 435.603(f)(4)), counted once with the child. + medicaid_household_size: [3, 3, 3] + +# A Household API partner reported this household (issue 9562): a New Jersey +# parent and an 18-year-old child with no relationship or tax-role inputs. +- name: Case 12, a New Jersey parent and an 18-year-old with no role inputs are a household of two. + period: 2026 + input: + people: + person1: + age: 45 + employment_income: 31_000 + person2: + age: 18 + households: + household: + members: [person1, person2] + state_code: NJ + output: + # The model builds the omitted marital units by the tax-role rules: the + # 18-year-old, under 19 and younger than the parent, gets their own and is + # the parent's dependent. $31,000 is above the head of household filing + # threshold, so both use the parent's tax household of 2 (42 CFR + # 435.603(f)(1)-(2)). Before those units were built, the model took the + # 18-year-old as the spouse, and the non-filer rules counted them twice, + # giving the parent 3. + medicaid_uses_non_filer_rules: [false, false] + medicaid_household_size: [2, 2] + +- name: Case 13, an 18-year-old in the spouse role on a head of household return counts once as the parent's child. + period: 2026 + input: + people: + person1: + age: 45 + own_children_in_household: 1 + is_tax_unit_head: true + person2: + age: 18 + is_tax_unit_spouse: true + tax_units: + tax_unit: + members: [person1, person2] + filing_status: HEAD_OF_HOUSEHOLD + households: + household: + members: [person1, person2] + state_code: NJ + output: + # The 18-year-old is input as the tax unit spouse, but the supplied filing + # status isn't joint, so neither is counted as the other's spouse. With no + # income neither files. The 18-year-old is the parent's + # child under 19 (435.603(f)(3)(ii)) and the parent is the 18-year-old's + # parent ((f)(3)(iii)). + is_tax_unit_spouse: [false, true] + tax_unit_is_filer: false + medicaid_uses_non_filer_rules: [true, true] + medicaid_household_size: [2, 2] + +- name: Case 14, a marital unit that also lists the child leaves the cohabiting spouse unidentified and counts each member once. + period: 2025 + input: + people: + person1: + age: 35 + own_children_in_household: 1 + person2: + age: 35 + own_children_in_household: 1 + person3: + age: 1 + marital_units: + marital_unit: + members: [person1, person2, person3] + tax_units: + tax_unit1: + members: [person1, person3] + cohabitating_spouses: true + tax_unit2: + members: [person2] + cohabitating_spouses: true + households: + household: + members: [person1, person2, person3] + state_code: CA + output: + # A parent's separate-return spouse is the other member of their marital + # unit, which here also lists the child, so no member is identified as the + # spouse. Each parent counts self, the cohabiting spouse once through the + # spouse count, and the child once as a member under 19. Taking the last + # member as the spouse would drop the child and give each parent 2. The + # child, claimed by one parent while living with both, uses the non-filer + # rules: self and both parents. + medicaid_uses_non_filer_rules: [true, true, true] + medicaid_household_size: [3, 3, 3] diff --git a/policyengine_us/variables/gov/hhs/medicaid/income/_non_filer_household.py b/policyengine_us/variables/gov/hhs/medicaid/income/_non_filer_household.py index 18ba4c140c3..ea7cd550f7f 100644 --- a/policyengine_us/variables/gov/hhs/medicaid/income/_non_filer_household.py +++ b/policyengine_us/variables/gov/hhs/medicaid/income/_non_filer_household.py @@ -7,12 +7,100 @@ ) from policyengine_us.variables.household.demographic.person._parent_links import ( has_parent_ids, + group_member_indices, household_has_parent_ids, household_member_indices, unlinked_parent, ) +def medicaid_non_filer_fallback_sum(person, period, values, spouse_sum, income=False): + """Deduplicate the existing family proxy when parent links are absent. + + Keep the proxy's family-level parent and child groups, and its tax-role + and cohabiting-spouse channels. The applicant and spouse take precedence + over relatives; parents take precedence over child-age relatives. For + income, keep own/spouse amounts signed, remaining parents netted within + each marital unit and floored, and remaining children's positive amounts. + ``spouse_sum`` retains the caller's fallback for an unidentified spouse. + + The spouse is the one ``spouse_sum`` counts: the other head or spouse of + a joint return (head_spouse_count 2), or the cohabiting spouse on a + separate return. A head or spouse on a return that isn't joint, such as + an inferred spouse under a supplied HEAD_OF_HOUSEHOLD filing status, has + no spouse here, so a child-age partner still counts once as a relative. + """ + values = np.asarray(values, dtype=np.float64) + total = values + spouse_sum + own = np.arange(person.count) + child = person("medicaid_non_filer_child_age_eligible", period) + parent = person("is_parent", period) + head_or_spouse = person("is_tax_unit_head_or_spouse", period) + head_spouse_count = person.tax_unit("head_spouse_count", period) + joint = head_or_spouse & (head_spouse_count == 2) + separate = ( + person.tax_unit("cohabitating_spouses", period) + & (head_spouse_count == 1) + & (head_or_spouse | person("claimed_as_dependent_on_another_return", period)) + ) + spouse = np.full(person.count, -1, dtype=int) + matches = np.zeros(person.count, dtype=int) + for member in group_member_indices(person.tax_unit): + included = (member >= 0) & (member != own) & joint & head_or_spouse[member] + spouse = np.where(included, member, spouse) + matches = matches + included + for member in group_member_indices(person.marital_unit): + included = (member >= 0) & (member != own) & separate + spouse = np.where(included, member, spouse) + matches = matches + included + # A larger, ambiguous group cannot identify which member is the spouse. + spouse = np.where(matches == 1, spouse, -1) + + if income: + marital_unit = person.marital_unit.reference_entity.members_entity_id + parent_income = person.marital_unit.sum(parent * values) + parent_count = person.marital_unit.sum(parent) + + for member in group_member_indices(person.family): + included = (member >= 0) & (member != own) & (member != spouse) + relative_parent = child & parent[member] + relative_child = child[member] & ~relative_parent + if income: + # Exclude direct members before netting the remaining parents; + # otherwise a young parent/spouse contributes in both groups. + own_parent = parent & (marital_unit == marital_unit[member]) + spouse_parent = ( + (spouse >= 0) + & parent[spouse] + & (marital_unit[spouse] == marital_unit[member]) + ) + remaining_income = ( + parent_income[member] + - own_parent * values + - spouse_parent * values[spouse] + ) + remaining_count = ( + parent_count[member] + - own_parent.astype(int) + - spouse_parent.astype(int) + ) + parent_share = np.divide( + np.maximum(0, remaining_income), + remaining_count, + out=np.zeros(person.count), + where=remaining_count > 0, + ) + amount = np.where( + relative_parent, parent_share, np.maximum(0, values[member]) + ) + else: + amount = values[member] + total = total + np.where( + included & (relative_parent | relative_child), amount, 0 + ) + return total + + def _shares_parent_id(parent_1, parent_2, member): """Whether each person shares a nonzero parent id with a co-resident.""" return ( @@ -81,8 +169,8 @@ def is_spouse(member): def medicaid_non_filer_member_sum(person, period, values): """Sum ``values`` once over each person's MAGI non-filer household. - Callers use this in households with parent links and keep their original - family-level expressions elsewhere. Under 42 CFR 435.603(f)(3) the + Callers use this in households with parent links and + medicaid_non_filer_fallback_sum elsewhere. Under 42 CFR 435.603(f)(3) the household is the individual and, if living with the individual, (i) the spouse, (ii) the individual's children under the age limit and (iii) for an individual under the age limit, their parents and their siblings under diff --git a/policyengine_us/variables/gov/hhs/medicaid/income/medicaid_household_income.py b/policyengine_us/variables/gov/hhs/medicaid/income/medicaid_household_income.py index 7decd3be91e..ca3958ac111 100644 --- a/policyengine_us/variables/gov/hhs/medicaid/income/medicaid_household_income.py +++ b/policyengine_us/variables/gov/hhs/medicaid/income/medicaid_household_income.py @@ -5,6 +5,7 @@ ) from policyengine_us.variables.gov.hhs.medicaid.income._non_filer_household import ( medicaid_filer_spouse_sum, + medicaid_non_filer_fallback_sum, medicaid_non_filer_member_sum, medicaid_tax_dependent_spouse_sum, ) @@ -33,10 +34,12 @@ class medicaid_household_income(Variable): "siblings are read from the whole family, and those relatives' " "amounts are added only when positive (each child's, and each " "couple's parents' netted), so a relative outside the household " - "cannot lower its income. An adult's own amount and their spouse's " - "are added signed; a child's own amount and their siblings' enter " - "with the family's children, only when positive. Unmarried " - "co-resident parents are each counted only when positive." + "cannot lower its income. The applicant's own amount and their spouse's " + "(the other head or spouse of a joint return, or a cohabiting spouse " + "filing separately) are added signed and excluded from the relatives' " + "groups. In a child-age applicant's household, a parent who is also " + "child-age is counted only as a parent. Unmarried co-resident parents " + "are each counted only when positive." ) definition_period = YEAR reference = ( @@ -46,7 +49,6 @@ class medicaid_household_income(Variable): ) def formula(person, period, parameters): - child_age_eligible = person("medicaid_non_filer_child_age_eligible", period) non_filer_rules = person("medicaid_uses_non_filer_rules", period) member_income = person("medicaid_household_income_member", period) required_to_file = person("medicaid_person_is_required_to_file", period) @@ -59,13 +61,17 @@ def formula(person, period, parameters): person("medicaid_magi_person", period), ) head_or_spouse = person("is_tax_unit_head_or_spouse", period) - head_or_spouse_count = head_or_spouse.astype(int) - head_spouse_income = person.tax_unit.sum(head_or_spouse_count * member_income) - same_unit_spouse_income = head_or_spouse_count * head_spouse_income - ( - head_or_spouse_count * member_income + head_spouse_count = person.tax_unit("head_spouse_count", period) + head_spouse_income = person.tax_unit.sum(head_or_spouse * member_income) + # As in medicaid_household_size, the other head or spouse is a + # same-unit spouse only on a joint return (head_spouse_count 2). + same_unit_spouse_income = where( + head_or_spouse & (head_spouse_count == 2), + head_spouse_income - member_income, + 0, ) cohabitating_separate = person.tax_unit("cohabitating_spouses", period) & ( - person.tax_unit("head_spouse_count", period) == 1 + head_spouse_count == 1 ) claimed_by_another_return = person( "claimed_as_dependent_on_another_return", period @@ -76,32 +82,8 @@ def formula(person, period, parameters): 0, ) spouse_income = same_unit_spouse_income + separate_spouse_income - # The non-filer household's parents and siblings are read from the - # whole family, which can include people outside the household, such - # as a grandparent who is also a parent there. So their amounts are - # added only when positive: each child's, and each couple's parents' - # netted together, so married parents' losses still offset each - # other's income. An adult's own and their spouse's amounts are added - # signed; a child's own amount is among the family's children. - family_child_income = person.family.sum( - child_age_eligible * max_(0, member_income) - ) - is_parent = person("is_parent", period) - couple_parent_income = person.marital_unit.sum(is_parent * member_income) - couple_parents = person.marital_unit.sum(is_parent) - parent_share = np.divide( - is_parent.astype(float), - couple_parents, - out=np.zeros_like(couple_parents, dtype=float), - where=couple_parents > 0, - ) - family_parent_income = person.family.sum( - parent_share * max_(0, couple_parent_income) - ) - non_filer_household_income = where( - child_age_eligible, - spouse_income + family_parent_income + family_child_income, - member_income + spouse_income + family_child_income, + non_filer_household_income = medicaid_non_filer_fallback_sum( + person, period, member_income, spouse_income, income=True ) # With parent links in the household, sum over the same members that # medicaid_household_size counts, adding every selected amount signed. diff --git a/policyengine_us/variables/gov/hhs/medicaid/income/medicaid_household_size.py b/policyengine_us/variables/gov/hhs/medicaid/income/medicaid_household_size.py index 1b01c40950e..8bf886f4bf0 100644 --- a/policyengine_us/variables/gov/hhs/medicaid/income/medicaid_household_size.py +++ b/policyengine_us/variables/gov/hhs/medicaid/income/medicaid_household_size.py @@ -5,6 +5,7 @@ ) from policyengine_us.variables.gov.hhs.medicaid.income._non_filer_household import ( medicaid_filer_spouse_sum, + medicaid_non_filer_fallback_sum, medicaid_non_filer_member_sum, medicaid_tax_dependent_spouse_sum, ) @@ -27,10 +28,7 @@ class medicaid_household_size(Variable): ) def formula(person, period, parameters): - child_age_eligible = person("medicaid_non_filer_child_age_eligible", period) non_filer_rules = person("medicaid_uses_non_filer_rules", period) - family_child_count = person.family.sum(child_age_eligible) - family_parent_count = person.family.sum(person("is_parent", period)) head_or_spouse = person("is_tax_unit_head_or_spouse", period) same_unit_spouse_count = head_or_spouse.astype(int) * ( person.tax_unit("head_spouse_count", period) - 1 @@ -45,10 +43,8 @@ def formula(person, period, parameters): int ) * cohabitating_separate.astype(int) spouse_count = same_unit_spouse_count + separate_spouse_count - non_filer_household_size = where( - child_age_eligible, - spouse_count + family_parent_count + family_child_count, - 1 + spouse_count + family_child_count, + non_filer_household_size = medicaid_non_filer_fallback_sum( + person, period, np.ones(person.count), spouse_count ) # With parent links in the household, count each member of the # applicant's own non-filer household once, spouse included.