Stability selection

examples/stability.py asks which of 39 characteristics predict the wages of California’s workers aged 25 to 64 reliably, and bounds how many of the answers can be false. A single lasso’s selection changes from sample to sample, and its cross-validated penalty keeps many predictors that matter little. Stability selection keeps only what is selected again and again on subsamples.

from acs_data import WAGE_PREDICTORS, load_acs, rhs
from penalized_stream import stability_selection_stream

acs = load_acs()
stab = stability_selection_stream(f"log_wage ~ {rhs(WAGE_PREDICTORS)}", acs,
                                  groups="factors", cutoff=0.75, pfer=1.0)
print(stab.summary_text())
stability selection: 5 of 39 stable at cutoff 0.75; q = 6 per subsample, 100 subsamples; expected false selections at most 0.942 (unimodal)
obs: 149,192
┌───────────────────────┬─────────────┬──────────┐
│ candidate             ┆ probability ┆ selected │
╞═══════════════════════╪═════════════╪══════════╡
│ C(female)             ┆ 1.0         ┆ true     │
│ C(english)            ┆ 1.0         ┆ true     │
│ C(insurance_employer) ┆ 1.0         ┆ true     │
│ C(insurance_medicaid) ┆ 1.0         ┆ true     │
│ C(education)          ┆ 0.9         ┆ true     │
│ C(race)               ┆ 0.72        ┆ false    │
└───────────────────────┴─────────────┴──────────┘

The summary also prints the formula on its first line, which is left out here.

What was run

With groups="factors", each characteristic’s indicators are one candidate, selected or left out whole by a group lasso. There are 39 candidates and about 2,000 indicators.

The rows are split into 20 shards in the single pass over the data. Each of 100 subsamples is half of the shards, in 50 complementary pairs (Shah and Samworth 2013). On each subsample, the group lasso’s path runs until q = 6 candidates have entered. A candidate is stable when at least 75% (cutoff) of the subsamples select it.

pfer=1.0 asks that the expected number of false selections be at most 1. With the cutoff, that sets q. Here, under Shah and Samworth’s unimodality assumption (stabs’ default), the bound is 0.942. The subsamples’ fits use only the shards’ cross-products, so the 100 group lassos add no passes over the data. On a laptop with 8 cores the script takes about a minute: 20 seconds for the pass, and the rest for the 100 group lasso paths over about 2,000 indicators, run 8 at a time.

Reading the result

Five characteristics are stable: sex, English proficiency, employer-provided and Medicaid coverage, and education. Race is selected in 72% of the subsamples, just under the cutoff.

Stability selection answers a narrower question than “what matters most”. It finds the candidates that the path brings in among its first six, again and again. The group lasso penalizes each factor by the square root of its number of indicators, as grpreg does. So a factor with a few strong indicators, such as sex or coverage, enters the path before one whose effect is spread over hundreds of levels, such as occupation or industry. Those predict wages too, but not among the first six. To see where each factor enters, use stab.path, the share of subsamples selecting each candidate at each step of the path. A larger pfer allows a larger q, at the cost of more expected false selections.

stab.tidy() lists every candidate’s selection probability, highest first:

┌───────────────────────┬─────────────┬──────────┐
│ candidate             ┆ probability ┆ selected │
╞═══════════════════════╪═════════════╪══════════╡
│ C(female)             ┆ 1.0         ┆ true     │
│ C(english)            ┆ 1.0         ┆ true     │
│ C(insurance_employer) ┆ 1.0         ┆ true     │
│ C(insurance_medicaid) ┆ 1.0         ┆ true     │
│ C(education)          ┆ 0.9         ┆ true     │
│ …                     ┆ …           ┆ …        │
│ C(hispanic)           ┆ 0.0         ┆ false    │
│ C(marital)            ┆ 0.0         ┆ false    │
│ C(nativity)           ┆ 0.0         ┆ false    │
│ C(citizen)            ┆ 0.0         ┆ false    │
│ C(entry_decade)       ┆ 0.0         ┆ false    │
└───────────────────────┴─────────────┴──────────┘