Logistic Variable Selection via Pólya–Gamma SSVS
Python · R · Part 9 of the variable-selection arc — binary outcomes
Overview
Part 9 of the variable-selection arc: selection for a binary outcome. Most applied selection problems have a binary response — disease or not, default or not — which breaks the clean conjugacy the earlier notebooks relied on: the logistic likelihood is not Gaussian, so the spike-and-slab Gibbs of Part 1 does not apply directly. The elegant fix is Pólya–Gamma data augmentation (Polson, Scott & Windle 2013): introduce a latent weight per observation and the logistic likelihood becomes conditionally Gaussian in the coefficients — after which the exact same conjugate SSVS sweep works. The showcase is the South African Heart Disease data (the logistic example in Elements of Statistical Learning): 462 men, coronary heart disease against nine risk factors — which of the nine belong in the model? Because is small, we run the SSVS search and enumerate all logistic models exactly — bridging Part 1 and Part 2 for a binary outcome — cross-checked against PyMC and R's BAS.
The Pólya–Gamma trick — a non-conjugate likelihood made Gaussian
Logistic regression with a spike-and-slab prior on the standardized predictors: with the usual narrow-spike / wide-slab prior and . The likelihood has no conjugate prior, so is not a tidy normal and the Part-1 Gibbs stalls. Polson–Scott–Windle show that with a latent Pólya–Gamma variable per observation, the likelihood contribution becomes Gaussian in with pseudo-response and weight . So the Gibbs sweep is: (1) draw with the Devroye/PSW exact sampler; (2) draw as a weighted-least-squares normal with the spike-and-slab prior variances, exactly as in Part 1; (3) draw the indicators from the spike/slab density ratio. And exactly: with only nine predictors we also enumerate all models, each logistic model's marginal likelihood by a Laplace approximation with the binomial Fisher information — giving exact posterior model and inclusion probabilities. Engine: a self-contained logitsel.py.
Results
Five of nine risk factors survive. Both the Pólya–Gamma search and the exact enumeration keep age, family history, tobacco, type-A behaviour and LDL cholesterol, and drop systolic BP, adiposity, obesity and alcohol — exactly the model Elements of Statistical Learning reaches by stepwise selection, recovered here as a posterior over models with uncertainty attached. age is certain (inclusion ≈ 1), family history nearly so, the others firmly in but graded. A famous non-finding: selection is about conditional, not marginal, relevance — and here the two genuinely part ways. Adiposity, on its own about as correlated with heart disease as the retained LDL (), is dropped because its signal is already carried by the factors it travels with (age, obesity, LDL); type-A behaviour, only weakly correlated marginally (), is kept for the independent signal it adds — the logistic posterior sees through the confounding. The selected model is also interpretable: coronary risk climbs ~5% in odds per year of age, and each retained factor (family history most) shifts the whole age–risk curve up additively on the log-odds scale, tracking the observed proportions. Selection is free here: the five-variable model's predicted probabilities track the full nine-variable model's almost exactly () and generalize slightly better out of sample (CV AUC 0.782 vs 0.770) — the dropped factors were contributing variance, not signal. Three ways agree: the from-scratch Gibbs, PyMC's native logistic SSVS, and exact enumeration all select the same five — the augmentation is what lets the whole Gaussian selection machinery of Part 1 carry over to binary data (and, unchanged, to counts and multinomial beyond).
Notebooks
Downloads
References
- Polson, N. G., Scott, J. G. & Windle, J. (2013). Bayesian inference for logistic models using Pólya–Gamma latent variables. Journal of the American Statistical Association 108(504), 1339–1349. — the Pólya–Gamma augmentation reproduced here
- George, E. I. & McCulloch, R. E. (1993). Variable selection via Gibbs sampling. Journal of the American Statistical Association 88(423), 881–889. — the spike-and-slab SSVS sweep carried over to the binary case
- Hastie, T., Tibshirani, R. & Friedman, J. (2009). The Elements of Statistical Learning (2nd ed.), §4.4.2. Springer. — the South African heart-disease logistic example and stepwise selection
- Rousseauw, J. et al. (1983). Coronary risk factor screening in three rural communities. South African Medical Journal 64, 430–436. — the source of the heart-disease data
- Clyde, M. A., Ghosh, J. & Littman, M. L. (2011). Bayesian adaptive sampling for variable selection and model averaging. Journal of Computational and Graphical Statistics 20(1), 80–101. — the R
BAScross-check - Barbieri, M. M. & Berger, J. O. (2004). Optimal predictive model selection. Annals of Statistics 32(3), 870–897. — the median-probability model and inclusion probabilities