The math behind choicer: hierarchical Bayesian multinomial probit
Source:vignettes/articles/hierarchical_mnp_math.Rmd
hierarchical_mnp_math.RmdThis article gives a self-contained description of the hierarchical
Bayesian multinomial probit with iid utility shocks (HMNP) implemented
by run_hmnprobit() and src/hmnprobit.cpp.
Shared hierarchy code is in src/hb_internal.h and sampling
primitives are in src/bayes_samplers.h and
src/rng.h.
Model boundary. HMNP is not a hierarchical version of the unrestricted-covariance MNP fitted by
run_mnprobit(). HMNP imposes iid utility-level normal shocks with a common expanded variance. Its substitution flexibility comes from persistent taste heterogeneity and pooled alternative effects. The standalone MNP instead estimates a full covariance matrix of utility differences but has no respondent hierarchy.
1. Model and data layout
Respondents are , tasks are , and is the possibly unbalanced set of inside alternatives. The implicit outside option is . Structural covariates are and alternative characteristics are . Utilities on the sampler’s raw scale are
The outside utility is stochastic, not a deterministic zero threshold. The sampler retains one latent outside utility per task. It operates in undifferenced utility space, so each augmented error is independent and unbalanced choice sets require no special covariance submatrix.
Taste and alternative hierarchies are
All taste coordinates are normal. HMNP does not offer
rc_dist: exponentiating a coordinate would make the
regression conditional non-Gaussian and destroy the fully conjugate
update used by the kernel.
2. Exact relationship to an MNP in differences
Difference each inside utility against the outside:
Within a task,
Thus the difference-error covariance for a task with inside alternatives is
with pairwise correlation
.
This is a fixed equicorrelation structure, not an estimated unrestricted
covariance. On HMNP’s reported normalization
,
the diagonal is 2 and the off-diagonal is 1. On
run_mnprobit()’s convention of dividing by the first
diagonal element, the corresponding matrix would have diagonal 1 and
off-diagonal
.
This distinction is essential when comparing the two classes.
3. Identification and per-draw normalization
The observational choice rule is unchanged by the positive scaling map
The likelihood therefore has no information about one common utility scale. The chain samples a proper raw-scale posterior with free and raw-scale priors. Every retained draw is then mapped to the identified convention :
Normalization is applied draw by draw. For example, in general. Top-level coefficient, covariance, alternative-effect, respondent-effect, and diagnostic summaries all use these normalized draws. The raw chain is retained as an expansion diagnostic but is deliberately excluded from the automatic convergence warning because it is not an identified estimand.
The proper raw-scale priors are not invariant under this map: they induce a joint prior over all normalized quantities. Consequently the expanded variance prior is not ignorable. Prior-predictive analysis and sensitivity to , as well as to the and priors, are part of serious use.
The outside option fixes utility location: its systematic utility is zero, so there is no base inside alternative and no sum-to-zero constraint on . v0.2.0 requires the outside option.
For
,
has variance
.
With reported
,
choicer’s coefficient is therefore
times the coefficient from
glm(..., binomial(link="probit")), whose latent error
variance is normalized to one. The test suite uses this binary identity
as a validation check.
4. Priors and augmented posterior
The priors shared with HMNL are
The inverse-Wishart convention is
Defaults are , , , , , and . The raw prior mean of , when it exists, is .
The default alternative-effect prior is through
or optionally . HMNP adds
with defaults . Throughout, is shape–scale: .
Let be the set of latent utilities in which each observed choice exceeds every other latent in its task. The augmented posterior is proportional to
where counts every inside latent and one outside latent per task.
5. One fully conjugate Gibbs iteration
5.1 Latent utilities
Within each task the kernel scans inside rows in stored order and then the outside latent. Because shocks are independent, an untruncated inside conditional is
and the outside conditional is . If alternative is chosen, its current update is truncated below by the maximum current latent among all ; each nonchosen update is truncated above by the current latent of . The bounds use already-updated values for preceding coordinates and old values for later coordinates, making this an ordinary scalar Gibbs scan of the truncated joint normal. Ties have probability zero.
5.2 Respondent coefficients
Let stack respondent ’s inside rows, their latent utilities, and the vector repeating the relevant . Define the precomputed Gram matrix . Then
After each draw the row cache is refreshed. The outside latents do not enter this regression because their design vectors are zero.
5.3 Alternative effects
Given augmented utilities, different appear in disjoint normal regressions and are conditionally independent. Let be all inside rows for alternative , , and . Then
These draws can be work-shared safely. This is the key computational contrast with HMNL’s serial, coupled softmax sweep.
6. Initialization, storage, and diagnostics
The kernel starts , , , , , and , regardless of nonzero prior means. Chosen latents start at and nonchosen latents at , including the outside latent. Burn-in, rather than an optimizer, moves the chain away from this feasible state.
The C++ kernel records raw draws of
,
vech,
,
,
,
and
.
At recording time it divides
,
,
and
by the current
before Welford updates or cube storage. The R wrapper applies the same
per-draw normalization to all hierarchical chains and constructs
object$draws; raw chain-1 versions are retained with
_raw names. object$chains contains normalized
plus raw
for every requested chain. Chains run sequentially; their seeds are
offset by one.
The same rank-normalized folded
split-,
bulk/tail ESS, MCSE, trace, and
worst-
conventions described for HMNL apply. summary() may display
the raw
diagnostic for transparency, but the automatic convergence warning
excludes it because movement along the expansion scale is not
convergence of an identified estimand. vech(W) is retained
but also omitted from the automatic table; it should be checked
explicitly across object$chains, particularly in
cross-sectional data. Normalized parameters, every
,
prior sensitivity, and posterior predictive behavior are the relevant
checks.
keep_beta_i="draws" is guarded using approximately
bytes per chain times the number of sequential chains, because all
returned C++ cubes coexist before the final object is assembled. The fit
object exposes chain-1 respondent summaries/draws; hierarchical draws
from every chain remain in object$chains.
7. Choice probabilities and Gauss–Hermite quadrature
On the identified scale , condition on the shock of candidate . With systematic utilities and ,
The product includes the outside option when
is inside and every inside alternative when
.
predict.choicer_hb() evaluates this one-dimensional
integral separately for every candidate using 20-node physicists’
Gauss–Hermite quadrature. If
integrate
,
then
The resulting candidate probabilities are divided by their numerical sum to remove quadrature drift. This final renormalization is numerical, not part of the probit model.
As with HMNL, population prediction pairs posterior draw with one ; it is a Monte Carlo average over heterogeneity. Individual prediction uses stored when available and otherwise plugs in the posterior mean. New alternatives receive . Post-estimation simulations use R’s RNG.
Finite-difference elasticities() and
diversion_ratios() use these predicted aggregate shares and
common random-number paths, exactly as for HMNL. wtp() uses
drawwise population-mean coefficient ratios; all HMNP coefficients are
normal, so those means are the components of
.
The EV1 logsum identity does not apply to normal shocks. Although
is mathematically defined and can be evaluated numerically or by
simulation, v0.2.0 does not implement that calculation.
logsum() and consumer_surplus() therefore
error for HMNP rather than applying an incorrect logit formula.
8. Computational contract
One persistent OpenMP region contains the whole chain. A work-shared respondent pass performs latent updates, draws, and cache refreshes; a work-shared alternative pass draws ; another respondent pass computes RSS. Hierarchy draws, fixed-order reductions, recording, and interrupt checks are master-only. Worker paths use hand-written dense Cholesky and triangular solvers and never call R’s API or BLAS/LAPACK.
At iteration , RNG tags drive respondent latent sweeps, drive respondent coefficient draws, drive alternative effects, and drive , and then in a fixed order from the last shared stream. This partition is collision-free even when . Results are deterministic for a fixed seed and execution environment; byte identity across thread counts or toolchains is not an API guarantee.
References
- Albert, J. H., & Chib, S. (1993). Bayesian analysis of binary and polychotomous response data. Journal of the American Statistical Association, 88(422), 669–679.
- Gelman, A. (2006). Prior distributions for variance parameters in hierarchical models. Bayesian Analysis, 1(3), 515–534.
- Liu, J. S., & Wu, Y. N. (1999). Parameter expansion for data augmentation. Journal of the American Statistical Association, 94(448), 1264–1274.
- Makalic, E., & Schmidt, D. F. (2016). A simple sampler for the horseshoe estimator. IEEE Signal Processing Letters, 23(1), 179–182.
- McCulloch, R. E., & Rossi, P. E. (1994). An exact likelihood analysis of the multinomial probit model. Journal of Econometrics, 64(1–2), 207–240.
- Rossi, P. E., Allenby, G. M., & McCulloch, R. (2005). Bayesian Statistics and Marketing. Wiley.
- Train, K. E. (2009). Discrete Choice Methods with Simulation (2nd ed.). Cambridge University Press.
- Vehtari, A., Gelman, A., Simpson, D., Carpenter, B., & Bürkner, P.-C. (2021). Rank-normalization, folding, and localization: an improved for assessing convergence of MCMC. Bayesian Analysis, 16(2), 667–718.