Appendix A — Appendix
A.1 R Packages for Discrete Choice
This book estimated everything by hand on principle; your research need not. The ecosystem below is where hand-coded understanding meets production convenience — and each package served as a validation target somewhere in these pages, so you have seen their output next to ours.
mlogit (Croissant 2020) is the canonical starting point: multinomial, nested, and mixed logit (by MSL with Halton draws), plus heteroskedastic and probit variants, built on the dfidx indexed-data-frame layer whose conventions mirror our long-format contract (Chapter 4). It validated our MNL (Chapter 8), nested logit (Chapter 10), and mixed logit (Chapter 13). Its formula interface — three parts, separated by |, for alternative-varying/generic, individual-specific, and alternative-varying/alternative-specific-coefficient variables — takes an afternoon to internalize and repays it.
gmnl (Sarrias and Daziano 2017) extends the frequentist heterogeneity menu: latent class, mixed-mixed, and G-MNL models with one interface. A caution from experience (Chapter 11): its current CRAN build has decayed against the modern mlogit data layer — verify against its own examples before trusting it with your data. Rchoice (Sarrias 2016) covers random-parameter binary and ordered models, and its documentation contains one of the most compact published tutorials on simulated-likelihood mechanics. mixl (Molloy et al. 2021) compiles user-specified utilities to C++ for very large mixed logit problems — the industrial version of Chapter 9’s advice.
bayesm (Rossi, Allenby, and McCulloch 2005) is the Bayesian workhorse and the direct ancestor of this book’s Part III–IV samplers: rhierMnlRwMixture is Chapter 17 with a mixture-of-normals population layer, rmnpGibbs is Chapter 19’s route 2, and hierarchical MNP, volumetric models, and more live alongside. Its data formats are list-heavy and its identification conventions (differencing base, post-sampling normalization) must be matched carefully — Chapter 19’s validation section is a worked example of exactly that care.
Beyond CRAN’s choice-specific corner: Stan (via rstan/brms/cmdstanr) estimates any model in this book by Hamiltonian Monte Carlo — less transparent than your own Gibbs sampler, far more general; the Apollo package is the transportation field’s full-featured platform; and Sawtooth Software’s Lighthouse Studio is the commercial conjoint standard whose HB engine is, at heart, Chapter 17’s sampler.
A.2 Notation Glossary
| Symbol | Meaning | First appears |
|---|---|---|
| \(n = 1, \ldots, N\) | decision-makers (respondents) | Chapter 3 |
| \(t = 1, \ldots, T\) | choice situations (tasks) per person | Chapter 4 |
| \(j = 1, \ldots, J\) | alternatives within a task | Chapter 4 |
| \(r = 1, \ldots, R\) | simulation draws | Chapter 1 |
| \(s = 1, \ldots, S\) | MCMC iterations | Chapter 15 |
| \(y\), \(y_{nt}\), \(y_{ntj}\) | choice outcome; indicator form | Chapter 1, Chapter 8 |
| \(\mathbf{x}_{ntj}\), \(\mathbf{X}\) | attribute vector; stacked design matrix | Chapter 1, Chapter 4 |
| \(\boldsymbol{\beta}\), \(\boldsymbol{\beta}_n\) | utility coefficients; person-specific version | Chapter 1, Chapter 13 |
| \(\boldsymbol{\varepsilon}\), \(\varepsilon_{ntj}\) | unobserved utility components | Chapter 1 |
| \(h(\cdot)\), \(f(\cdot)\) | behavioral rule; density of unobservables | Chapter 1 |
| \(U_{ntj}\), \(V_{ntj}\) | total and representative utility | Chapter 7 |
| \(P_{ntj}\) | choice probability | Chapter 7 |
| \(\ell(\cdot)\), \(L(\cdot)\) | log-likelihood; likelihood | Chapter 5 |
| \(s(\boldsymbol{\beta})\), \(H(\boldsymbol{\beta})\) | score (gradient); Hessian | Chapter 5 |
| \(\hat{\boldsymbol{\beta}}\) | an estimate (MLE unless stated) | Chapter 5 |
| \(\pi_c\), \(\boldsymbol{\beta}_c\) | class share; class coefficients | Chapter 11 |
| \(\bar{\boldsymbol{\beta}}\), \(\Sigma\) | population mean and covariance of tastes | Chapter 13 |
| \(\lambda\) | nested logit dissimilarity parameter | Chapter 10 |
| \(I_{ntm}\) | inclusive value (log-sum) of nest \(m\) | Chapter 10 |
| \(\Omega\) | raw \(J \times J\) MNP error covariance | Chapter 18 |
| \(\tilde\Omega\) | differenced \((J-1) \times (J-1)\) covariance, normalized so \(\tilde\omega_{11}=1\): \(\tilde\Omega = M\Omega M' / (M\Omega M')_{11}\) | Chapter 18 |
| \(W\) | unnormalized differenced covariance sampled in Gibbs; identified: \(W/w_{11}\) and \(\boldsymbol{\beta}/\sqrt{w_{11}}\) | Chapter 19 |
| \(\tau\) | proposal step size (MCMC); budget (ext. 2) | Chapter 15, Chapter 22 |
| \(\gamma\) | no-choice (none) constant | Chapter 22 |
| \(IW(\nu_0, V_0)\) | inverse-Wishart prior | Chapter 17 |
| \(\widehat{R}\), ESS | convergence ratio; effective sample size | Chapter 15 |
| \(\mathbf{d}_{nt}\) | latent base-differenced utilities \((d_2, d_3)\) | Chapter 19 |
| \(M\), \(A_j\) | differencing matrix; per-chosen-alternative transformation | Chapter 18, Chapter 19 |
| \(g = 1, \ldots, G\); \(w_g\) | grid points and weights (flexible mixing) — not the covariance elements \(w_{11}, w_{12}, w_{22}\) of Chapter 19 | Chapter 22 |
| \(g(\boldsymbol{\beta})\) | function of parameters (WTP ratio, shares) — distinct from the grid index \(g\) | Chapter 21 |
| \(CV\) | compensating variation (log-sum change, in dollars) | Chapter 21 |
| \(\alpha\) | acceptance probability (MCMC); budget-utility weight (ext. 2) | Chapter 15, Chapter 22 |
A.3 Common Numerical Errors and Their Symptoms
A field guide to the failures this book staged deliberately, for the day they happen to you accidentally.
The likelihood returns -Inf or NaN. Almost always exp() overflow/underflow or log(0). Check for a missing log-sum-exp max-shift (Section 8.3), a probability that underflowed before its log (Chapter 5), or mis-scaled data (price in dollars instead of thousands, Chapter 6).
The optimizer “converges” instantly at the starting values. Gradient numerically zero at the start — typically a flat region from saturated probabilities (again scaling) or a bug returning a constant. Evaluate the objective at a few hand-picked points before blaming the optimizer (Chapter 5’s candidate-scoring table is the template).
Estimates match no truth, but two implementations agree. Then the estimator is fine and the comparison is wrong: check identification normalizations (scale, base alternative, reference levels — Section 7.5, Chapter 18) before checking code. Sign-flipped, uniformly-rescaled estimates are the signature of a differencing-convention mismatch (Chapter 19’s bayesm footnote).
An MSL fit wanders or won’t converge. Are the draws fixed across evaluations? Re-drawn randomness inside the objective is the classic self-inflicted wound (Chapter 12, demonstrated). Also check draw counts via the doubling diagnostic.
Wild individual-level estimates. Per-person estimation with small \(T\) — perfect separation and incidental parameters (Chapter 14). The cure is pooling: conditional means or a hierarchy, never a bigger iteration cap.
MCMC traces drift and never settle, but the answers look right. If the drifting quantities are unidentified (MNP scale) while identified functions of them are stable, the sampler is healthy — diagnose the normalized series (Chapter 19). If identified quantities drift: too little burn-in, a step size at an extreme acceptance rate (Chapter 15), or blocks updating on stale values (a coding bug).
Mixture or hierarchy estimates depend on the run. Local maxima (multiple starts, compare summits — Chapter 11) or label switching (order classes by a coefficient before comparing). For hierarchical variance parameters that refuse to approach zero: that is the inverse-Wishart floor, a prior property, not a bug (Chapter 17).
Grouped computations silently wrong. The sort-order contract (Chapter 4): rowsum(), ave(), and index-broadcasting all assume rows grouped as promised, and person-level weights indexed at the wrong level (task vs person, Chapter 11) fail without errors. stopifnot() guards are cheap; use them.