diff --git a/changelog.d/spouse-ignores-dependent-separation.fixed.md b/changelog.d/spouse-ignores-dependent-separation.fixed.md new file mode 100644 index 00000000000..f1d7ce2b73a --- /dev/null +++ b/changelog.d/spouse-ignores-dependent-separation.fixed.md @@ -0,0 +1 @@ +Limited the inferred spouse's separation check to the head and selected spouse candidate. diff --git a/docs/usage/microsimulation.md b/docs/usage/microsimulation.md index c7ef7197d5a..d31439b825f 100644 --- a/docs/usage/microsimulation.md +++ b/docs/usage/microsimulation.md @@ -161,12 +161,14 @@ partner in their marital unit. A head without one takes the next-oldest such adult, except an adult who meets the qualifying child age test against the head (26 USC 152(c)(3)): under 19, or under 24 if a full-time student, and younger than the head, or permanently and totally disabled at any age. That adult stays -a dependent. No spouse is inferred when any member of the unit is separated, -and a separated member doesn't count toward a couple. When a situation omits +a dependent. PolicyEngine infers no spouse when the head or selected spouse +candidate is separated. It selects the candidate before checking separation, +without promoting a younger adult; member order breaks equal-age ties. A +separated member doesn't count toward a couple. When a situation omits marital units, Core puts everyone in one marital unit, so plain age order applies. A minor living without a parent is left with no head. -This rule has four known limitations. Supply `is_tax_unit_head`, +This rule has three known limitations. Supply `is_tax_unit_head`, `is_tax_unit_spouse` or `tax_unit_role_input` for these households: - When a tax unit holds a married couple and an older adult outside their @@ -183,11 +185,6 @@ This rule has four known limitations. Supply `is_tax_unit_head`, becomes the head's dependent, whatever their income. Examples are a spouse living apart in a care facility, or a self-supporting sibling, whose income then leaves the return. -- When a separated adult outside a married couple's marital unit shares their - tax unit, the couple heads the unit but no spouse is inferred, since a unit - with a separated member infers none. The other member of the couple becomes - a dependent. Under the law a spouse can't be the other spouse's dependent, - and the couple could file jointly. The Microcosm build carries its constructor's filing status in a `filing_status_input` column. No variable has that name, so the column is diff --git a/policyengine_us/tests/core/test_tax_unit_role_input_properties.py b/policyengine_us/tests/core/test_tax_unit_role_input_properties.py index a1e27e688f5..204d6585bca 100644 --- a/policyengine_us/tests/core/test_tax_unit_role_input_properties.py +++ b/policyengine_us/tests/core/test_tax_unit_role_input_properties.py @@ -10,7 +10,7 @@ roles equal an independent implementation of age ordering. The oldest adult heads the unit, earliest member on ties, skipping adults input as tax unit dependents unless every adult is one; the next such adult is the spouse - unless any member of the unit is separated. The generated situations pass + unless the head or that adult is separated. The generated situations pass no marital units, so Core puts everyone in one marital unit and the couple-first head and partner-first spouse rules reduce to age order. 4. Filing status is computed: no supplied status is read, so a unit files @@ -120,20 +120,22 @@ def _situation(units, pin_explicitly=False): } -def _age_rule(ages, separated, dependent_input=None): - # Mirrors the fallback as it stands, with marital units omitted (see - # invariant 3). Adults input as tax unit dependents are skipped unless - # every adult is one (#9630). Any separated member blocks every spouse; - # that unit-wide gate is a known defect (#9620), so update this reference - # when it is fixed. +def _age_rule(ages, separated, dependent_input=None, head_input=None): + """Independent age order for situations without marital-unit inputs.""" adults = [i for i, age in enumerate(ages) if age >= 18] if dependent_input is not None: non_dependents = [i for i in adults if not dependent_input[i]] if non_dependents: adults = non_dependents - head = min(adults, key=lambda i: (-ages[i], i)) if adults else None - candidates = [] if any(separated) else [i for i in adults if i != head] + head = head_input + if head is None: + head = min(adults, key=lambda i: (-ages[i], i)) if adults else None + candidates = [i for i in adults if i != head] spouse = min(candidates, key=lambda i: (-ages[i], i)) if candidates else None + if spouse is not None and ( + (head is not None and separated[head]) or separated[spouse] + ): + spouse = None return head, spouse diff --git a/policyengine_us/tests/core/test_tax_unit_spouse_separation_invariants.py b/policyengine_us/tests/core/test_tax_unit_spouse_separation_invariants.py new file mode 100644 index 00000000000..97d35062962 --- /dev/null +++ b/policyengine_us/tests/core/test_tax_unit_spouse_separation_invariants.py @@ -0,0 +1,171 @@ +"""Invariants for the inferred tax unit spouse when members are separated. + +Separation under 26 U.S.C. 7703 concerns the filer's own marriage, so only +the head's or the would-be spouse's `is_separated` can leave a tax unit +without a spouse. The would-be spouse is the oldest head-or-spouse candidate +other than the head; candidates are adults not input as dependents (every +adult when all are). These situations omit marital units, so head and +spouse selection follows age order. Core breaks equal-age ties by member order. + +Hypothesis draws batches of tax units of one to five people, with tied ages, +children, separated members and, in turn, no role inputs, input dependent +flags, or an input head. A seeded population of 300 units adds breadth. Each +batch runs as one vectorized simulation that also holds a twin of every unit +in which every member other than the head and the would-be spouse has +`is_separated` flipped. For every tax unit: + +1. Structure: at most one spouse, who is neither the head nor a child. +2. Differential: head and spouse equal a pure-Python statement of the rule. +3. Separation of anyone but the head and the would-be spouse never changes + the spouse: each unit and its twin get the same spouse. +""" + +import numpy as np +import pytest +from hypothesis import HealthCheck, given, settings +from hypothesis import strategies as st + +from policyengine_us import Simulation +from policyengine_us.tests.core.test_tax_unit_role_input_properties import _age_rule + +YEAR = 2024 +ADULT_AGE = 18 +AGES = [6, 17, 18, 25, 30, 38, 40, 75] +MODES = ["no_roles", "dependents", "head"] + + +@st.composite +def tax_units(draw): + size = draw(st.integers(1, 5)) + members = [ + { + "age": draw(st.sampled_from(AGES)), + "separated": draw(st.booleans()), + "dependent": draw(st.booleans()), + } + for _ in range(size) + ] + return {"members": members, "head": draw(st.integers(0, size - 1))} + + +def _seeded_units(n=300, seed=20261006): + rng = np.random.default_rng(seed) + units = [] + for _ in range(n): + size = int(rng.integers(1, 6)) + members = [ + { + "age": int(rng.choice(AGES)), + "separated": bool(rng.random() < 0.3), + "dependent": bool(rng.random() < 0.4), + } + for _ in range(size) + ] + units.append({"members": members, "head": int(rng.integers(0, size))}) + return units + + +def _reference(unit, mode): + """Adapt the shared age-order reference to this test's input modes.""" + members = unit["members"] + return _age_rule( + [m["age"] for m in members], + [m["separated"] for m in members], + [m["dependent"] for m in members] if mode != "no_roles" else None, + unit["head"] if mode == "head" else None, + ) + + +def _twin(unit, mode): + """The unit with every member but the head and would-be spouse's + separation flipped.""" + members = unit["members"] + head, _ = _reference(unit, mode) + keep = {head} + # The would-be spouse is the spouse the rule finds when nobody is separated. + calm = {**unit, "members": [{**m, "separated": False} for m in members]} + keep.add(_reference(calm, mode)[1]) + flipped = [ + m if i in keep else {**m, "separated": not m["separated"]} + for i, m in enumerate(members) + ] + return {**unit, "members": flipped} + + +def _situation(units, mode): + people, tax_unit_groups, households = {}, {}, {} + for u, unit in enumerate(units): + names = [] + for i, member in enumerate(unit["members"]): + name = f"p{u}_{i}" + person = { + "age": {YEAR: member["age"]}, + "is_separated": {YEAR: member["separated"]}, + } + if mode in ("dependents", "head"): + person["is_tax_unit_dependent"] = {YEAR: member["dependent"]} + if mode == "head": + person["is_tax_unit_head"] = {YEAR: i == unit["head"]} + people[name] = person + names.append(name) + tax_unit_groups[f"t{u}"] = {"members": names} + households[f"h{u}"] = {"members": names, "state_code": {YEAR: "TX"}} + return { + "people": people, + "tax_units": tax_unit_groups, + "households": households, + } + + +def _check(units, mode): + batch = units + [_twin(unit, mode) for unit in units] + sim = Simulation(situation=_situation(batch, mode)) + head = np.asarray(sim.calculate("is_tax_unit_head", YEAR), dtype=bool) + spouse = np.asarray(sim.calculate("is_tax_unit_spouse", YEAR), dtype=bool) + start = 0 + spouses = [] + for u, unit in enumerate(batch): + size = len(unit["members"]) + unit_head = head[start : start + size] + unit_spouse = spouse[start : start + size] + ages = [m["age"] for m in unit["members"]] + start += size + + # 1. Structure. + assert unit_spouse.sum() <= 1, (mode, unit) + assert not (unit_spouse & unit_head).any(), (mode, unit) + assert all(age >= ADULT_AGE for age, s in zip(ages, unit_spouse) if s) + + # 2. Differential against the reference rule. + expected_head, expected_spouse = _reference(unit, mode) + assert list(np.flatnonzero(unit_head)) == ( + [] if expected_head is None else [expected_head] + ), (mode, unit, unit_head) + assert list(np.flatnonzero(unit_spouse)) == ( + [] if expected_spouse is None else [expected_spouse] + ), (mode, unit, unit_spouse) + spouses.append(list(np.flatnonzero(unit_spouse))) + + # 3. Each unit and its twin share a spouse. + assert spouses[: len(units)] == spouses[len(units) :] + + +# A batch's cost is mostly per-variable overhead, so each example is a large +# batch and there are few examples. +SETTINGS = dict( + max_examples=10, + deadline=None, + derandomize=True, + suppress_health_check=[HealthCheck.too_slow, HealthCheck.data_too_large], +) + + +@settings(**SETTINGS) +@given(st.sampled_from(MODES), st.lists(tax_units(), min_size=5, max_size=40)) +def test_tax_unit_spouse_separation_invariants(mode, units): + _check(units, mode) + + +@pytest.mark.parametrize("mode", MODES) +def test_seeded_population(mode): + _check(_seeded_units(), mode) diff --git a/policyengine_us/tests/policy/baseline/household/demographic/tax_unit/filing_status.yaml b/policyengine_us/tests/policy/baseline/household/demographic/tax_unit/filing_status.yaml index f993c6326da..8cfa2a74806 100644 --- a/policyengine_us/tests/policy/baseline/household/demographic/tax_unit/filing_status.yaml +++ b/policyengine_us/tests/policy/baseline/household/demographic/tax_unit/filing_status.yaml @@ -251,3 +251,43 @@ output: # Each parent has 5,100 of taxable benefits, not below 4,400. filing_status: SINGLE + +- name: A separated adult dependent does not stop a married couple filing jointly. + period: 2024 + input: + people: + head: + age: 40 + is_tax_unit_dependent: false + employment_income: 50_000 + spouse: + age: 38 + is_tax_unit_dependent: false + employment_income: 30_000 + dependent: + age: 18 + is_tax_unit_dependent: true + is_separated: true + marital_units: + couple_marital_unit: + members: [head, spouse] + dependent_marital_unit: + members: [dependent] + tax_units: + tax_unit: + members: [head, spouse, dependent] + households: + household: + members: [head, spouse, dependent] + state_code: TX + output: + filing_status: JOINT + tax_unit_married: true + # Rev. Proc. 2023-34: 2024 joint standard deduction is 29,200. + standard_deduction: 29_200 + # Both spouses' wages, 50,000 + 30,000, less 29,200. + taxable_income: 50_800 + # Continuous 2024 joint brackets: 10% of 23,200 plus 12% of (50,800 - 23,200). + income_tax_before_credits: 5_632 + # The 18-year-old dependent qualifies for the 500 credit for other dependents. + income_tax: 5_132 diff --git a/policyengine_us/tests/policy/baseline/household/demographic/tax_unit/is_tax_unit_head.yaml b/policyengine_us/tests/policy/baseline/household/demographic/tax_unit/is_tax_unit_head.yaml index 50ff322a476..8e6a4c04908 100644 --- a/policyengine_us/tests/policy/baseline/household/demographic/tax_unit/is_tax_unit_head.yaml +++ b/policyengine_us/tests/policy/baseline/household/demographic/tax_unit/is_tax_unit_head.yaml @@ -218,9 +218,9 @@ members: [parent, separated_adult, partner] state_code: TX output: - # A unit with a separated member infers no spouse, so the two-person - # marital unit is not a couple that can file jointly. The oldest adult - # heads the unit. + # The separated adult doesn't form a couple for head selection. The + # oldest adult heads the unit, and the selected spouse candidate's + # separation leaves the unit without a spouse. is_tax_unit_head: [true, false, false] is_tax_unit_spouse: [false, false, false] filing_status: SINGLE @@ -249,7 +249,7 @@ output: # With marital units omitted, Core puts all three adults in one marital # unit. It isn't a two-person unit, so the two non-separated adults aren't - # a couple, and the oldest adult heads the unit. A unit with a separated - # member infers no spouse. + # a couple, and the oldest adult heads the unit. That head's separation + # leaves the unit without a spouse. is_tax_unit_head: [true, false, false] is_tax_unit_spouse: [false, false, false] diff --git a/policyengine_us/tests/policy/baseline/household/demographic/tax_unit/is_tax_unit_spouse.yaml b/policyengine_us/tests/policy/baseline/household/demographic/tax_unit/is_tax_unit_spouse.yaml index ceef0f946c5..46cf7a67e48 100644 --- a/policyengine_us/tests/policy/baseline/household/demographic/tax_unit/is_tax_unit_spouse.yaml +++ b/policyengine_us/tests/policy/baseline/household/demographic/tax_unit/is_tax_unit_spouse.yaml @@ -330,3 +330,246 @@ is_tax_unit_spouse: [false, false] is_tax_unit_dependent: [false, true] filing_status: HEAD_OF_HOUSEHOLD + +- name: A separated adult dependent does not remove the filer's spouse. + period: 2024 + input: + people: + head: + age: 40 + is_tax_unit_dependent: false + spouse: + age: 38 + is_tax_unit_dependent: false + dependent: + age: 18 + is_tax_unit_dependent: true + is_separated: true + tax_units: + tax_unit: + members: [head, spouse, dependent] + output: + is_tax_unit_head: [true, false, false] + is_tax_unit_spouse: [false, true, false] + tax_unit_married: true + +- name: A separated elderly dependent older than the couple does not remove the spouse. + period: 2024 + input: + people: + head: + age: 40 + spouse: + age: 38 + parent: + age: 75 + is_tax_unit_dependent: true + is_separated: true + tax_units: + tax_unit: + members: [head, spouse, parent] + output: + is_tax_unit_spouse: [false, true, false] + +- name: A separated younger adult who is neither head nor spouse does not remove the spouse. + period: 2024 + input: + people: + head: + age: 40 + spouse: + age: 38 + other_adult: + age: 30 + is_separated: true + tax_units: + tax_unit: + members: [head, spouse, other_adult] + output: + is_tax_unit_spouse: [false, true, false] + +- name: A separated head has no spouse in the tax unit. + period: 2024 + input: + people: + head: + age: 40 + is_separated: true + other_adult: + age: 38 + tax_units: + tax_unit: + members: [head, other_adult] + output: + is_tax_unit_head: [true, false] + is_tax_unit_spouse: [false, false] + tax_unit_married: false + +# PolicyEngine selects the spouse candidate before checking separation and +# doesn't promote a younger adult when that candidate is separated. +- name: A separated second-oldest adult is not the spouse, and no younger adult takes the role. + period: 2024 + input: + people: + head: + age: 40 + separated_adult: + age: 38 + is_separated: true + younger_adult: + age: 30 + tax_units: + tax_unit: + members: [head, separated_adult, younger_adult] + output: + is_tax_unit_spouse: [false, false, false] + tax_unit_married: false + +- name: Separation only affects the spouse in its own tax unit. + period: 2024 + input: + people: + head_a: + age: 40 + spouse_a: + age: 38 + dependent_a: + age: 20 + is_tax_unit_dependent: true + is_separated: true + head_b: + age: 50 + is_separated: true + adult_b: + age: 45 + tax_units: + tax_unit_a: + members: [head_a, spouse_a, dependent_a] + tax_unit_b: + members: [head_b, adult_b] + households: + household: + members: [head_a, spouse_a, dependent_a, head_b, adult_b] + output: + is_tax_unit_head: [true, false, false, true, false] + is_tax_unit_spouse: [false, true, false, false, false] + tax_unit_married: [true, false] + +- name: A younger separated adult does not stop the next-oldest adult being the spouse. + period: 2024 + input: + people: + head: + age: 40 + separated_adult: + age: 25 + is_separated: true + other_adult: + age: 30 + tax_units: + tax_unit: + members: [head, separated_adult, other_adult] + output: + is_tax_unit_spouse: [false, false, true] + +- name: A separated dependent does not remove the spouse when the head is an input. + period: 2024 + input: + people: + head: + age: 40 + is_tax_unit_head: true + spouse: + age: 38 + dependent: + age: 19 + is_tax_unit_dependent: true + is_separated: true + tax_units: + tax_unit: + members: [head, spouse, dependent] + output: + is_tax_unit_spouse: [false, true, false] + +- name: With every adult input as a dependent, a third adult's separation leaves the spouse. + period: 2024 + input: + people: + oldest: + age: 40 + is_tax_unit_dependent: true + second: + age: 38 + is_tax_unit_dependent: true + third: + age: 20 + is_tax_unit_dependent: true + is_separated: true + tax_units: + tax_unit: + members: [oldest, second, third] + output: + is_tax_unit_head: [true, false, false] + is_tax_unit_spouse: [false, true, false] + +- name: With tied ages, the first non-separated candidate becomes the spouse. + period: 2024 + input: + people: + head: + age: 50 + other_adult: + age: 38 + separated_adult: + age: 38 + is_separated: true + tax_units: + tax_unit: + members: [head, other_adult, separated_adult] + output: + is_tax_unit_head: [true, false, false] + is_tax_unit_spouse: [false, true, false] + tax_unit_married: true + +- name: With tied ages, a separated first candidate leaves the unit without a spouse. + period: 2024 + input: + people: + head: + age: 50 + separated_adult: + age: 38 + is_separated: true + other_adult: + age: 38 + tax_units: + tax_unit: + members: [head, separated_adult, other_adult] + output: + is_tax_unit_head: [true, false, false] + is_tax_unit_spouse: [false, false, false] + tax_unit_married: false + +- name: An older separated adult leaves the marital couple as head and spouse. + period: 2024 + input: + people: + older_adult: + age: 75 + is_separated: true + head: + age: 50 + spouse: + age: 48 + tax_units: + tax_unit: + members: [older_adult, head, spouse] + marital_units: + older_adult_unit: + members: [older_adult] + couple: + members: [head, spouse] + output: + is_tax_unit_head: [false, true, false] + is_tax_unit_spouse: [false, false, true] + tax_unit_married: true diff --git a/policyengine_us/variables/household/demographic/tax_unit/is_tax_unit_head.py b/policyengine_us/variables/household/demographic/tax_unit/is_tax_unit_head.py index 098e2d7cdea..2cf75ad3d7a 100644 --- a/policyengine_us/variables/household/demographic/tax_unit/is_tax_unit_head.py +++ b/policyengine_us/variables/household/demographic/tax_unit/is_tax_unit_head.py @@ -28,8 +28,7 @@ def formula(person, period, parameters): # couple heads it, even if another adult is older. When a situation # omits marital units, Core puts everyone in one unit, so this changes # nothing there: a two-person unit gives the same head. - # A separated member doesn't form such a couple: is_tax_unit_spouse - # gives no one the spouse role in a unit with a separated member. + # A separated member doesn't form such a couple for head selection. # NOTE: the older adult then becomes the couple's dependent whatever # their income. If that adult files instead, claiming a couple who # don't file jointly, supply is_tax_unit_head or tax_unit_role_input. diff --git a/policyengine_us/variables/household/demographic/tax_unit/is_tax_unit_spouse.py b/policyengine_us/variables/household/demographic/tax_unit/is_tax_unit_spouse.py index 1408fa7e122..0b771c3de88 100644 --- a/policyengine_us/variables/household/demographic/tax_unit/is_tax_unit_spouse.py +++ b/policyengine_us/variables/household/demographic/tax_unit/is_tax_unit_spouse.py @@ -9,7 +9,10 @@ class is_tax_unit_spouse(Variable): entity = Person label = "Spouse of tax unit" definition_period = YEAR - reference = "https://www.law.cornell.edu/uscode/text/26/152#c_3" + reference = ( + "https://www.law.cornell.edu/uscode/text/26/152#c_3", + "https://www.law.cornell.edu/uscode/text/26/7703#a_2", + ) def formula(person, period, parameters): tax_unit = person.tax_unit @@ -18,10 +21,9 @@ def formula(person, period, parameters): supplied = tax_unit("tax_unit_roles_supplied", period) # Otherwise only non-head adults can be spouses, skipping input # dependents. - is_separated = tax_unit.any(person("is_separated", period)) candidate = head_or_spouse_candidates(person, period) head = person("is_tax_unit_head", period) - eligible = candidate & ~head & ~is_separated + eligible = candidate & ~head # A marital unit holds a married, cohabiting couple, and # is_tax_unit_head takes the head from such a couple when the tax # unit has one, so the head's partner in their marital unit is the @@ -39,9 +41,8 @@ def formula(person, period, parameters): # test is still paired with the head, even if they could be a # qualifying relative. A permanently and totally disabled adult # outside the head's marital unit becomes a dependent whatever their - # income. And when a separated adult shares the unit with a couple who - # heads it, the head's partner isn't inferred as the spouse. Supply - # is_tax_unit_spouse or tax_unit_role_input for these households. + # income. Supply is_tax_unit_spouse or tax_unit_role_input for these + # households. marital_unit = person.marital_unit.reference_entity.members_entity_id head_marital_unit = tax_unit.max(where(head, marital_unit, -1)) in_head_marital_unit = marital_unit == head_marital_unit @@ -60,6 +61,12 @@ def formula(person, period, parameters): eligible & ~meets_age_test, ) next_oldest_adult = person.get_rank(tax_unit, -age, eligible) == 0 + # Legal separation concerns the head's own marriage (26 USC 7703). + # Select before checking separation, without promoting another adult; + # member order breaks equal-age ties. + separated = person("is_separated", period) + head_or_spouse_separated = tax_unit.any((head | next_oldest_adult) & separated) + next_oldest_adult = next_oldest_adult & ~head_or_spouse_separated # An explicit is_tax_unit_head input still wins over a supplied role, # so keep the head out of the spouse role either way. supplied_spouse = (role == role.possible_values.SPOUSE) & ~head diff --git a/policyengine_us/variables/household/demographic/tax_unit/tax_unit_role_input.py b/policyengine_us/variables/household/demographic/tax_unit/tax_unit_role_input.py index 613873695c7..d742e619183 100644 --- a/policyengine_us/variables/household/demographic/tax_unit/tax_unit_role_input.py +++ b/policyengine_us/variables/household/demographic/tax_unit/tax_unit_role_input.py @@ -15,4 +15,4 @@ class tax_unit_role_input(Variable): default_value = TaxUnitRole.UNSPECIFIED definition_period = YEAR label = "Supplied tax unit role" - documentation = "The person's role in their tax unit - head, spouse or dependent - as assigned by the tax-unit constructor that built a dataset, such as the Microcosm US build. When every member of a tax unit has a supplied role, is_tax_unit_head and is_tax_unit_spouse use it, so the constructor's head, its spouse pairing and its dependency claims all hold: a younger reference person can head a couple, an adult student stays a dependent, and a minor living without a parent can head a return. The roles only say who is head, spouse or dependent; filing_status is still computed from the unit's members and the filing rules. UNSPECIFIED (the default) means the role was not supplied, and the role variables fall back to age ordering: the oldest adult is the head, skipping adults input as tax unit dependents unless every adult in the unit is one, except that the older member of a couple sharing a two-person marital unit in the tax unit heads it. The spouse is the head's partner in their marital unit; a head without one takes the next-oldest such adult who doesn't meet the qualifying child age test against the head (under 19, or under 24 if a full-time student, and younger than the head, or permanently and totally disabled). No spouse is inferred when any member of the unit is separated. When marital units are omitted, everyone shares one marital unit, so plain age order applies." + documentation = "The person's role in their tax unit - head, spouse or dependent - as assigned by the tax-unit constructor that built a dataset, such as the Microcosm US build. When every member of a tax unit has a supplied role, is_tax_unit_head and is_tax_unit_spouse use it, so the constructor's head, its spouse pairing and its dependency claims all hold: a younger reference person can head a couple, an adult student stays a dependent, and a minor living without a parent can head a return. The roles only say who is head, spouse or dependent; filing_status is still computed from the unit's members and the filing rules. UNSPECIFIED (the default) means the role was not supplied, and the role variables fall back to age ordering: the oldest adult is the head, skipping adults input as tax unit dependents unless every adult in the unit is one, except that the older member of a couple sharing a two-person marital unit in the tax unit heads it. The spouse is the head's partner in their marital unit; a head without one takes the next-oldest such adult who doesn't meet the qualifying child age test against the head (under 19, or under 24 if a full-time student, and younger than the head, or permanently and totally disabled). No spouse is inferred when the head or selected spouse candidate is separated. When marital units are omitted, everyone shares one marital unit, so plain age order applies."