Bayesian Synthetic Control with a Soft Simplex Constraint (BVS-SS)#
Overview#
BVS-SS arXiv:2503.06454 is a Bayesian synthetic control estimator that wraps two ideas around the standard SCM regression \(\mathbf{y}_1 = \mathbf{Y}_0\mathbf{w} + \boldsymbol{\varepsilon}\):
Spike-and-slab variable selection. Each donor is either active (\(\gamma_j = 1\)) or excluded (\(\gamma_j = 0,\ w_j = 0\)), with a Bernoulli prior on inclusion. This handles high-dimensional panels where \(N_0\) (donor count) is comparable to or exceeds \(T_0\), and provides posterior inclusion probabilities \(P(\gamma_j = 1 \mid \mathbf{y}_1)\) that quantify donor relevance.
Soft simplex constraint. Selected weights are drawn around a Dirichlet mean \(\boldsymbol{\mu}_\gamma\) with a learnable variance \(\nu\). When \(\nu \to 0\) the prior collapses to the hard simplex of Abadie & Gardeazabal (2003); when \(\nu \to \infty\) it becomes an unconstrained spike-and-slab regression. The posterior of \(\nu\) tells the user whether the simplex constraint is supported by the data.
Compared to other Bayesian SCMs in mlsynth, BVS-SS is the only
one that simultaneously selects donors and estimates how strictly
the simplex should hold. This makes it the right tool when (a) the
donor pool is large, (b) you suspect some donors are irrelevant, and
(c) the appropriateness of the simplex constraint is itself a
modeling question (e.g. Hong Kong handover, Basque conflict, NFP tax
evasion — all cases where the treated unit’s level may legitimately
exceed any convex combination of donors).
Sampling is by a custom Metropolis-within-Gibbs scheme implemented in
pure numpy + scipy — no PyMC, NumPyro, or JAX
dependencies.
The Bayesian SC family#
mlsynth carries three Bayesian synthetic-control estimators; they differ in what they place a prior on, and BVSS is the soft-simplex donor-selection member.
Bayesian Synthetic Control Methods (BSCM) (Kim, Lee and Gupta) – shrinkage (horseshoe or spike-and-slab) on unconstrained donor weights; a pure-numpy Gibbs sampler, and it reports donor weights.
Bayesian Synthetic Control with a Soft Simplex Constraint (BVS-SS) (Xu and Zhou) – spike-and-slab donor selection on a soft simplex whose tightness is learned; a pure-numpy Metropolis-within-Gibbs sampler, and it reports donor weights and inclusion probabilities.
Bayesian Factor Synthetic Control (BFSC) (Pinkney) – a Bayesian latent-factor model, not a donor weighting; NUTS through the
[bayes]optional dependency, and it reports a counterfactual credible band and no donor weights.
Reach for a weighting prior (BVSS, Bayesian Synthetic Control Methods (BSCM)) when you want interpretable donor weights; reach for Bayesian Factor Synthetic Control (BFSC) when a shared factor structure – not a weighted average of donors – is the right model for the untreated outcome.
When to use this estimator#
The donor pool is large relative to the pre-period (\(N_0 \gtrsim T_0\)). The classical SCM quadratic program has no unique solution and Lasso-style alternatives tend to over-select; BVS-SS’s spike-and-slab structure recovers a sparse subset and converges to the oracle estimator as the sample grows.
You suspect some donors are irrelevant and want a probability statement, not an eyeball judgement, about which donors to trust.
The appropriateness of the simplex constraint is itself a modeling question — e.g. Hong Kong handover, Basque conflict, NFP tax evasion, all cases where the treated unit’s level may legitimately exceed any convex combination of donors.
A concrete example: an anti-corruption policy announcement may have depressed luxury-watch imports, and you have one treated customs category, a short monthly pre-period, and dozens of candidate donor categories. BVS-SS selects a sparse handful of donor categories, returns the posterior of the ATT, and — through the learned variance \(\nu\) — reports whether the watch series sits inside the convex hull of the donors or genuinely outside it.
Notation#
Let \(j = 1\) denote the treated unit, with all units \(\mathcal{N} \coloneqq \{1, \dots, N\}\) and donor pool \(\mathcal{N}_0 \coloneqq \mathcal{N} \setminus \{1\}\) of cardinality \(N_0\). Time runs over \(t \in \mathcal{T} \coloneqq \{1, \dots, T\}\), 1-indexed; the intervention takes effect after period \(T_0\), splitting \(\mathcal{T}\) into the pre-period \(\mathcal{T}_1 \coloneqq \{t \in \mathcal{T} : t \le T_0\}\) (of length \(T_0\)) and the post-period \(\mathcal{T}_2 \coloneqq \{t \in \mathcal{T} : t > T_0\}\).
The treated series is \(\mathbf{y}_1 = (y_{11}, \dots, y_{1T})^\top\) with scalar outcomes \(y_{1t}\); each donor \(j \in \mathcal{N}_0\) contributes a series \(\mathbf{y}_j\), stacked into the donor matrix \(\mathbf{Y}_0 \coloneqq [\mathbf{y}_j]_{j \in \mathcal{N}_0} \in \mathbb{R}^{T \times N_0}\) (one column per donor); column \(j\) is written \(\mathbf{Y}_{0,j}\). Donor weights are \(\mathbf{w} \in \mathbb{R}^{N_0}\), with inclusion indicators \(\boldsymbol{\gamma} \in \{0,1\}^{N_0}\) (\(\gamma_j = 1\) if donor \(j\) is active). The active-donor submatrix is \(\mathbf{Y}_{0,\gamma}\), its Dirichlet mean \(\boldsymbol{\mu}_\gamma\). The synthetic counterfactual is \(\widehat{\mathbf{y}}_1 \coloneqq \mathbf{Y}_0\mathbf{w}\) with entries \(\widehat{y}_{1t}\), the per-period effect is \(\tau_t \coloneqq y_{1t} - \widehat{y}_{1t}\), and the ATT is \(\widehat{\tau} \coloneqq |\mathcal{T}_2|^{-1} \sum_{t \in \mathcal{T}_2} \tau_t\). Page-specific symbols: the observation precision \(\phi\) (inverse error variance), the soft-simplex variance \(\nu\) (Dirichlet-mean spread; small \(\nu\) tightens toward the hard simplex), and the Dirichlet concentration \(\alpha\). Following the canon, \(\tau\) is reserved for the treatment effect: the soft-constraint variance is \(\nu\), the symbol the paper writes \(\tau\).
Mathematical Formulation#
Let \(\mathbf{y}_1 \in \mathbb{R}^{T_0}\) be the pre-treatment outcome of the treated unit and \(\mathbf{Y}_0 \in \mathbb{R}^{T_0 \times N_0}\) the contemporaneous donor matrix (restricted here to \(\mathcal{T}_1\)). Both are demeaned column-wise using the pre-treatment means before entering the sampler (this matches the paper’s working setup and makes the soft-simplex prior numerically well-conditioned).
Likelihood and Hierarchical Prior#
The Gaussian likelihood is
The hierarchical prior over \((\mathbf{w}, \boldsymbol{\mu}, \nu, \phi, \boldsymbol{\gamma})\) from Eq. (2) of the paper is
with the convention that \(\mu_j = w_j = 0\) whenever \(\gamma_j = 0\). The fixed-\(\alpha = 1\) case (uniform Dirichlet on the active simplex) is what BVS-SS implements in this package; the paper’s simulations and both empirical applications use this setting.
Interpreting the soft-constraint variance \(\nu\) is the key modeling insight:
As \(\nu \downarrow 0\), the prior of \(\mathbf{w}_\gamma\) concentrates at \(\boldsymbol{\mu}_\gamma \in \Delta^{|\gamma| - 1}\), i.e. the hard simplex.
As \(\nu \uparrow \infty\), the prior on \(\mathbf{w}_\gamma\) is effectively uninformative, recovering an unconstrained spike-and-slab regression à la Kim et al. (2020).
The posterior of \(\nu\) is therefore a data-driven indicator of whether the simplex constraint is appropriate for the application at hand. The paper proves (Theorem 4) that as \(\nu \to \infty\) the BVS-SS posterior of \(\boldsymbol{\gamma}\) becomes identical to the unconstrained spike-and-slab posterior, so the data really does pick between the two regimes through \(\nu\).
Marginal Likelihood and Posterior Conditionals#
A Woodbury-identity calculation (Eq. (4) of the paper) yields
with the two repeated quantities
The \(\phi\) and \(\mathbf{w}_\gamma\) full conditionals are conjugate (Eqs. (6)–(7)):
The \(\nu\) conditional has no closed form. The \((\boldsymbol{\gamma}, \boldsymbol{\mu})\) block is the technically interesting piece — it cannot be updated coordinate-wise (the simplex constraint \(\sum_{j: \gamma_j = 1} \mu_j = 1\) makes single-coordinate moves degenerate) so the paper introduces a two-coordinate Gibbs update over pairs \((\gamma_j, \gamma_{j'}, \mu_j, \mu_{j'})\).
Metropolis-within-Gibbs Sampler (Algorithm 1)#
One outer iteration performs three updates in order.
Pair update for \((\gamma_i, \gamma_j, \mu_i, \mu_j)\). For each unordered pair \(i < j\), fix \(\mu_{-(i,j)}\) and define the residual mass \(s = 1 - \sum_{k \neq i, j} \mu_k\). Three cases follow:
\(s = 0\): the simplex constraint forces \(\mu_i = \mu_j = 0\), no draw needed.
\(s > 0\): enumerate the four possible inclusion patterns \((\gamma_i, \gamma_j) \in \{(0,0), (1,0), (0,1), (1,1)\}\). The \((0,0)\) case is infeasible (would violate the simplex). The other three have closed-form conditional posterior probabilities (Lemma S2 of the paper). When the drawn pattern is \((1, 1)\), the conditional distribution of \(\mu_i\) is the univariate truncated normal
\[\mu_i \;\sim\; \mathcal{N}_{(0,\,s)}\!\left(\beta_{i,j},\; (\phi \Lambda_{i,j})^{-1}\right), \qquad \mu_j = s - \mu_i,\]where (Lemma S1)
\[\Lambda_{i,j} \;=\; (\mathbf{Y}_{0,i} - \mathbf{Y}_{0,j})^\top \boldsymbol{\Sigma}_{\gamma^{ij}, \nu} (\mathbf{Y}_{0,i} - \mathbf{Y}_{0,j}), \quad \beta_{i,j} \;=\; \frac{1}{\Lambda_{i,j}}\, (\mathbf{Y}_{0,i} - \mathbf{Y}_{0,j})^\top \boldsymbol{\Sigma}_{\gamma^{ij}, \nu} \!\left(\mathbf{y}_1 - s\,\mathbf{Y}_{0,j} - \!\!\!\sum_{k \neq i, j} \mu_k\,\mathbf{Y}_{0,k}\right).\]
The pair-update sweep visits every \((i, j)\) pair once per outer iteration. With \(\alpha = 1\) all probabilities involve only the standard normal CDF and a single truncated-normal draw — no rejection sampling and no numerical integration.
Each of the three feasible cases is scored at its own inclusion vector. Eq. (11) of the paper defines
three different sets of two different cardinalities, and Lemma 2 indexes both the complexity factor \(A(\gamma, \nu)\) and the projector \(\boldsymbol{\Sigma}_{\gamma, \nu}\) by the state’s own vector. Scoring the one-donor cases at \(\gamma^{ij}\) gives them a residual that has had the other donor projected out of it, which inflates the \((1,1)\) probability and so the fitted model size; on the luxury-watch panel it moved the posterior mean model size to 9.19 against the paper’s 5.09.
One settled discrepancy, one open#
Both predate this page and both are shared with the authors’ own replication script, so neither is visible from a cross-validation against that script alone.
Settled: the complexity factor does not carry \(\nu^{-|\gamma|/2}\). The
statement of Lemma 2 gives \(A(\gamma, \nu)\) a factor
\(\nu^{-|\gamma|/2}\), inherited from the marginal likelihood in Eq. (4),
while the proof of the same lemma says \(A\) collapses to
\(\det(V_{\gamma,\nu})^{-1/2} (|\gamma| - 1)!\, p_0(|\gamma|)\) with no
such factor. The two are different samplers, because the factor depends on
\(|\gamma|\) and \(|\gamma^i| = \ell + 1\) while
\(|\gamma^{ij}| = \ell + 2\), so it cannot be absorbed into the normalising
constant. Restoring it was measured over twelve seeds on the luxury-watch
panel: the posterior mean model size goes to 21.60 against Table 6’s 5.09,
\(\phi\) to 18.94 against 20.86 and \(\nu\) to 0.0217 against 0.069 –
every summary further from the paper’s own table. The proof’s reading is the
one that reproduces the paper, and mlsynth follows it, as the authors’
script does.
Open: the posterior model size. At the benchmark’s 50 iterations the posterior mean model size is 2.77 over twelve seeds, and at 400 iterations 3.07 over three, against Table 6’s 5.09 from a 1000-iteration run. Chain length accounts for part of the gap and the trend has the right sign, but not for all of it at the lengths measured. The collapse corrected above was the larger term in the opposite direction, taking the same quantity to 9.19.
The counterfactual is built from \(\boldsymbol{\mu}\). Algorithm 1 of the
paper draws \(\mathbf{w}^{(t)}\) from its Eq. (7) conditional and forms the
counterfactual as \(\tilde{\mathbf{X}} \mathbf{w}^{(t)}\); Remark 2 permits
replacing that draw by its conditional mean, Eq. (8), to reduce the variance of
the ATT estimate. The authors’ script implements Remark 2. mlsynth uses
\(\boldsymbol{\mu}\) itself, which is neither, and
\(\mathbf{w} \to \boldsymbol{\mu}\) only as \(\nu \downarrow 0\).
How much that costs is measured. Evaluating both constructions on the same draws – so the comparison carries none of the sampler’s Monte-Carlo noise – the posterior mean ATT moves by 0.48 % of itself and the credible interval’s width by a factor of 0.999, over five seeds on the watch panel at 400 iterations. The per-seed width ratio ranges from 0.972 to 1.023, which is smaller than the seed-to-seed spread of the width itself. Switching to Eq. (8) would re-derive every pinned number on this page and in the benchmark for a change in the reported answer of under half a per cent.
\(\phi\) Gibbs draw. Plug the updated \(\mu\) into the closed-form Gamma conditional above.
\(\nu\) MH steps. Repeat for \(n_\nu\) iterations a log-random-walk proposal
with the lower boundary \(\log \nu_{\min}\) reflected (proposals below \(\nu_{\min}\) are mirrored back into the support). The acceptance ratio is
where the final \(\nu^\ast / \nu\) factor is the Jacobian of the log-space random walk.
Counterfactual Imputation and ATT#
The sampler returns posterior draws \(\{\boldsymbol{\mu}^{(s)}\}_{s = 1}^{S}\) after burn-in. The treated unit’s counterfactual at every period \(t\) is constructed from the column-demeaned donor matrix \(\widetilde{\mathbf{Y}}_0\) (using the same pre-treatment means as the sampler) via
where \(\bar y_{1,\mathrm{pre}}\) is the pre-treatment mean of the treated outcome. The post-treatment ATT per draw is
and the reported headline ATT is the posterior mean of \(\widehat{\tau}^{(s)}\). Credible intervals are percentile bands over \(\widehat{\tau}^{(s)}\) at level \(1 - \mathrm{ci\_alpha}\) (default 95 %). Pointwise bands on the counterfactual are computed analogously period-by-period.
BVS-SS computes the counterfactual directly from the \(\boldsymbol{\mu}\) posterior instead of drawing \(\mathbf{w}_\gamma\) from its Eq. (7) conditional. The paper’s own variance reduction is Remark 2 of Section 3.3, which replaces the draw by its Eq. (8) conditional mean \(V_{\gamma,\nu}^{-1}(\mathbf{Y}_{0,\gamma}^\top \mathbf{y}_1 + \nu^{-1}\boldsymbol{\mu}_\gamma)\), so the two agree only in the \(\nu \downarrow 0\) limit. See the open discrepancies above.
When BVS-SS Is the Right Tool#
The paper documents three settings where BVS-SS materially outperforms the classical SCM:
High-dimensional donor pools (Section 5.2). When
Nis comparable to or exceedsT_0, the standard quadratic program does not have a unique solution and Lasso-style alternatives tend to over-select. BVS-SS’s spike-and-slab structure recovers a sparse subset and converges to the oracle OLS estimator as the sample grows.Simplex-violating data (Section 5.2, \(\|\mathbf{w}^\ast\|_1 \in \{2, 3\}\)). When the true sum of weights exceeds 1 — as it plausibly does for outliers like Hong Kong’s GDP in the late 1990s — methods that enforce the hard simplex are biased, while BVS-SS’s posterior of \(\nu\) moves away from zero and the model adapts.
Anti-tax-evasion / anti-corruption policy evaluation (Section 6). Replicating Carvalho et al. (2018) and Shi & Huang (2023), BVS-SS recovers the published ATT magnitudes with substantially smaller credible intervals than Lasso-based ArCo, while selecting only ~2 donors on average instead of the entire pool.
A handy diagnostic is the posterior of \(\nu\): small
posterior mass near zero is a sign the data agrees with the simplex
constraint, while bulk away from zero is evidence to relax it.
results.simplex summarises it and results.posterior.tau holds the raw
draws; Reading the simplex verdict below says what the summary contains and
how to read it.
Assumptions (Xu & Zhou 2025)#
The paper proves high-dimensional strong selection consistency – the posterior probability of the true active-donor model converging to 1 under the true DGP – in Theorem 2, under the technical conditions A1-A5 (Section 4.1). Stated for the working \(\nu = 0\) (hard-simplex) limit:
Restricted eigenvalue on the donor matrix (A1). Each column \(\mathbf{Y}_{0,j}\) of the donor matrix satisfies \(\| \mathbf{Y}_{0,j} \|_2^2 = T_0\), and there exists \(\underline\lambda \in (0, 1]\) such that \(\lambda_{\min}(\mathbf{Y}_{0,\gamma}^\top \mathbf{Y}_{0,\gamma}) \ge T_0 \underline\lambda\) for every candidate model \(\gamma\) in the sparse model space \(\mathbb{S}_L\).
Remark. No two donors are perfectly collinear, no donor is a near-duplicate of a linear combination of a few others, and the minimum eigenvalue of every “reasonable-size” donor submatrix is bounded away from zero.
Inclusion-prior penalty (A2). The Bernoulli inclusion probability satisfies \(\theta / (1 - \theta) = N^{-c_\theta L}\) for some universal \(c_\theta > 0\).
Remark. The prior penalises large models geometrically in the donor count – a default \(\theta \approx 1/N\) keeps the prior expected model size around 1.
Noise-precision prior (A3). The Gamma prior on \(\phi\) has shape \(\kappa_1 \in (0, T_0]\) and rate \(\kappa_2 \in [0, \sigma^2 T_0 / 2]\).
Remark. The prior on the inverse error variance is not pathologically informative (neither shape nor rate scale faster than \(T_0\)).
True DGP and signal strength / \(\beta\)-min (A4). The true outcome is \(\mathbf{y}_1 \mid \mathbf{Y}_0 \sim \mathcal{N}(\mathbf{Y}_{0,\gamma^\ast} \boldsymbol{\mu}_{\gamma^\ast}^\ast, \sigma^2 \mathbf{I})\) with \(\ell^\ast \coloneqq |\gamma^\ast| \le L \wedge \sqrt{L \log N}\), \(\boldsymbol{\mu}_{\gamma^\ast}^\ast \in \Delta^{\ell^\ast - 1}\), and a lower bound on the smallest non-zero weight,
\[\min_{j \in \gamma^\ast} |\mu_j^\ast| \;\ge\; \frac{c_\mu \sigma \sqrt{L \log N}}{\underline\lambda \sqrt{T_0}}.\]Remark. The true donor pool is sparse, lies on the simplex, and every truly-active donor carries weight detectable above the noise floor. The \(\beta\)-min lower bound is the standard “signal large enough to identify” condition shared with all high-dimensional consistency theory (Yang et al. 2016).
Sample-size lower bound (A5). \(L \ge 3\) and \(T_0 \ge c_M \ell^\ast \log N\) for some \(c_M > 0\).
Remark. The pre-period must grow with the (log of) the donor pool size for selection consistency to take hold.
Theorem 2 (Xu & Zhou 2025). Under A1-A5, the posterior inclusion probability of the true model satisfies \(p(\gamma^\ast \mid \mathbf{y}_1) \xrightarrow{p^\ast} 1\) as \(T_0, N \to \infty\) along any allowed sequence. Theorem 3 then bounds the posterior expected predictive loss on the test (post-treatment) sample at the order \((T - T_0)\, \ell^\ast \log N / T_0\), which is the “oracle” rate for the constrained problem – i.e., BVS-SS is asymptotically as efficient as if an oracle had told you the true active set in advance.
For the soft-simplex limit \(\nu \to \infty\), Theorem 4 shows the BVS-SS posterior of \(\gamma\) converges to the unconstrained spike-and-slab posterior. The two regimes are genuine endpoints of the same family; the data picks between them through the learned posterior of \(\nu\).
When the assumptions bind: practical diagnostics#
Donor near-collinearity (A1). If two donors carry essentially the same pre-period information, the minimum eigenvalue of \(\mathbf{Y}_{0,\gamma}^\top \mathbf{Y}_{0,\gamma}\) is near zero on models that include both – the restricted-eigenvalue condition fails and the spike-and-slab will flip between them without ever converging on a single representative.
Plausibly violated when the donor pool contains near-clones (two product categories whose time series differ only by sampling noise; two states with essentially identical industry mix). Diagnostic: inspect
results.inclusion_probs– if two donors each show \(P(\text{included}) \approx 0.4\) with all others below 0.1, the model is splitting credit between near-duplicates. Drop one or merge them before refitting.Prior penalty scale (A2). A too-large \(\theta\) floods the posterior with large-model mass; a too-small one blocks even truly-active donors.
Plausibly violated when the default \(\theta\) was chosen blindly. Diagnostic: track the posterior model size
results.posterior.gamma.sum(axis=0); if its posterior mean is essentially the prior mean \(N \theta\), the data is not informing model size and you should tighten \(\theta\). The paper’s empirical applications use \(\theta = 0.2\).Sparse, simplex-supported truth (A4). Selection consistency requires that the true weight vector is sparse and on the simplex. If the truth is genuinely dense (many donors each contributing a small fraction) or genuinely off-simplex (weights summing to substantially more or less than 1), the consistency story does not apply – though the procedure still produces a well-defined posterior.
Plausibly violated when the treated unit is structurally outside the donor convex hull (Hong Kong handover; very extreme growth unit). Diagnostic:
results.simplex.tau_meanagainst its prior mean \(a_1 / a_2\), on a long chain. Measured over three donor orderings in Reading the simplex verdict below, that comparison separates the paper’s two panels by a factor of six – the luxury-watch panel it reports as supporting the constraint against the Hong Kong handover panel it uses to motivate relaxing one – whereresults.simplex.relative_deviationdoes not separate them at all. Read the latter for how large the departure is in weight units, not for which panel departs more. Well above the prior mean, reach for the unconstrained-spike-and-slab limit (Kim et al. 2020) or for an estimator that explicitly handles outside-hull treated units (Imperfect Synthetic Controls (ISCM)).Long-enough pre-period (A5). Selection consistency requires \(T_0 \gtrsim \ell^\ast \log N\). With 20 pre-period observations and 100 donors, you need at most \(\ell^\ast \le 20 / \log 100 \approx 4\) truly-active donors for the theory to apply – realistic in practice but a binding constraint at small \(T_0\).
Plausibly violated when the pre-period is short and the donor pool is wide. Diagnostic: monitor MCMC mixing diagnostics on the posterior model size; if the posterior of \(|\gamma|\) is unstable across chains (different seeds select markedly different active sets), the sample-size-vs-donor-count regime is too tight for stable selection. Either lengthen the pre-period (aggregate to a finer time grid) or pre-screen donors using domain knowledge.
Gaussian likelihood with shock independence. The model assumes \(y_{1t} \sim \mathcal{N}((\mathbf{Y}_0 \mathbf{w})_t, \phi^{-1})\) with iid errors. Strong autocorrelation in the pre-period residuals or heavy tails breaks the variance estimate that feeds into both \(\phi\) and the \(\beta\)-min threshold.
Plausibly violated when the outcome has unit-root-like persistence or heavy outliers. Diagnostic: ADF / KPSS on the pre-period residual of the OLS-on-included-donors fit; a non-stationary residual flags this. First-difference the outcome and donors before refitting, or move to a cycle-decomposing estimator (Synthetic Business Cycle (SBC)) before BVS-SS.
Posterior of \(\nu\) as the soft-simplex test. The single diagnostic that summarises the simplex-vs-unconstrained decision: small posterior mass of \(\nu\) near zero means the data agrees with the simplex; bulk above the prior mean means the data prefers the relaxation.
Practical rule of thumb: compare
results.simplex.tau_meanagainst the prior mean \(a_1 / a_2\). A posterior concentrated below the prior mean says the data did not ask for a relaxation; one sitting above it says the data pulled \(\nu\) up to buy room off the simplex. Measured at one setting on both of the paper’s own panels, the China-watches application lands at the prior mean and the Hong Kong handover case (Hsiao 2012, the motivation in Section 1.1) at seven times it – the ordering the paper’s argument predicts.Read
results.simplex.tau_q025andtau_q975alongside it. On both panels the 95 % credible set runs from the sampler’s lower bound to many times the prior mean, so the posterior mean summarises a diffuse posterior, and the level of \(\nu\) moves with the chain length and \(\theta\) where the ordering between panels does not. Reading the simplex verdict has the numbers.
Reading the simplex verdict#
results.simplex is the posterior’s answer to the question the paper sets
out to ask. Eight numbers, each analytic in the draws of \(\nu\),
\(\phi\) and \(|\gamma|\), so none of them depends on how the
counterfactual is built – the construction that is still open above.
Field |
What it is |
|---|---|
|
Posterior summaries of the soft-constraint variance. The fields keep the paper’s spelling \(\tau\); this page writes the same quantity \(\nu\), because \(\tau\) is the treatment effect. |
|
\(E[\sqrt{\nu / \phi}]\), the standard deviation of a single weight about its simplex centre, in weight units. |
|
\(E[\sqrt{|\gamma| \nu / \phi}]\). The coordinates are independent given the parameters, so their variances add and \(\sum_j w_j\) departs from one on this scale. |
|
|
|
Posterior mean \(|\gamma|\). |
Reading more than \(\nu\) itself matters because \(\nu\) is not in
weight units, and the comparison the paper makes – \(\nu\) against its
prior mean \(a_1 / a_2\) – answers whether the data asked for a relaxation,
not how large the relaxation it got was. \(\sqrt{\nu / \phi}\) is in
weight units, and a scatter of 0.05 means one thing spread over three donors
and another over thirty, which is what relative_deviation corrects for.
The two readings can point in different directions on the same panel, and when
they do, both are true: the data can decline to demand a large relaxation while
the fit still uses the room the prior gives it. California’s cigarette panel
below is such a case, with \(\nu\) at 0.033 against a prior mean of 0.1
and a scatter of 38 % of a typical weight.
Two panels, measured#
Section 1.1 of the paper motivates relaxing the simplex with Hsiao’s (2012)
Hong Kong handover panel, where the treated unit’s growth sits outside any
convex combination of its donors; Section 6.2’s application is the luxury-watch
panel this page replicates. Both ship in basedata/, so both can be read
at identical settings – 400 iterations, 200 discarded, \(\theta = 0.25\),
averaged over three seeds, with \(\nu\)’s prior mean at
\(a_1 / a_2 = 0.1\):
Panel |
\(\nu\) |
95 % set for \(\nu\) |
\(\sqrt{\nu/\phi}\) |
relative |
\(|\gamma|\) |
|---|---|---|---|---|---|
Luxury watches (\(T_0 = 35\), \(N = 87\)) |
0.099 |
(0.000, 0.973) |
0.037 |
14 % |
3.82 |
Hong Kong (\(T_0 = 44\), \(N = 24\)) |
0.700 |
(0.000, 5.936) |
0.070 |
23 % |
3.07 |
In that run the ordering the paper’s argument predicts holds on both readings: Hong Kong puts \(\nu\) an order of magnitude above the watch panel, and puts its scatter off the simplex at 23 % of a typical weight against 14 %. Only one of the two survives repetition.
The levels in that table are not reproducible, and the two readings do not
survive equally. Nothing in the model depends on the order the donors arrive
in, but the pair sweep visits \((i, j)\) in index order, so the chain does.
Over three donor orderings of the watch panel at these settings, \(\nu\)
comes out 0.099, 0.040 and 0.105 and relative_deviation 14 %, 5 % and 20 %;
Hong Kong gives 0.700 and 0.626, and 23 % and 17 %. The Path A table below, at
1000 iterations and \(\theta = 0.2\), puts the watch panel’s \(\nu\)
at 0.030.
So \(\nu\) separates these two panels and \(\sqrt{\nu/\phi}\)
against a typical weight does not. The \(\nu\) ranges do not come close to
touching, a factor of six apart at worst, while the relative_deviation
ranges overlap – the watch panel’s widest run reads above Hong Kong’s
narrowest, though Hong Kong is higher in each ordering where both were run.
Use \(\nu\) against its prior mean to compare panels, on a chain long
enough to have settled, and use relative_deviation to say how large the
departure is in weight units for the fit in front of you.
Neither credible set is tight. Both run from the sampler’s lower bound \(\nu_{\min}\) up to about ten times the prior mean on the watch panel and sixty times it on Hong Kong, so the posterior mean summarises a diffuse posterior, which is why the quantiles are fields and not something a reader has to go and compute. A diffuse posterior for \(\nu\) and a summary that moves with the chain are the same fact seen twice, and it is the sensitivity the open model-size item above describes.
Under Eq. (2) the weights are \(\boldsymbol{\mu} + N(0, (\nu/\phi) I)\),
so the scatter can be read as a probability: about a fifth of draws on each
panel carry at least one negative weight. Like relative_deviation, that
share does not tell the two panels apart, but in absolute terms it says the
non-negativity half of Abadie’s restriction is not approximately in force on
either.
Level, shape, and the intercept#
Abadie’s canonical estimator imposes three restrictions: no intercept,
\(\sum_j w_j = 1\), and \(w_j \ge 0\). BVS-SS softens the second and
third with \(\nu\) and leaves the first at the opposite extreme. The
demeaning in prepare_bvss_inputs() is
an improper uniform prior on an intercept, marginalized analytically: fitting
\((\mathbf{y}_1 - \bar y_{1,\mathrm{pre}}) =
\widetilde{\mathbf{Y}}_0 \mathbf{w}\) is fitting \(\mathbf{y}_1 =
(\bar y_{1,\mathrm{pre}} - \bar{\mathbf{Y}}_0^\top \mathbf{w}) +
\mathbf{Y}_0 \mathbf{w}\), so the level is free and unpenalised.
One consequence is that the verdict does not depend on the treated unit’s level
at all. Adding a constant to \(\mathbf{y}_1\) moves the intercept and
leaves \(\nu\), \(\phi\) and \(|\gamma|\) identical to ten
figures, which mlsynth/tests/test_bvss_simplex_diagnostics.py asserts.
Dropping the demeaning instead forces \(\alpha = 0\) and changes nothing
else, which asks which of the two relaxations a panel is leaning on. Three
panels from basedata/, free arm then forced-to-zero arm, at the
settings above:
Panel |
\(|\bar y_1| / s_{y_1}\) |
\(\sqrt{\nu/\phi}\) |
relative |
\(|\gamma|\) |
|---|---|---|---|---|
Luxury watches (monthly growth) |
0.09 |
0.0203 / 0.0191 |
5.4 % / 5.9 % |
2.51 / 2.45 |
Hong Kong (quarterly growth) |
0.75 |
0.0605 / 0.0599 |
17.3 % / 16.7 % |
2.78 / 2.74 |
California cigarette sales (levels) |
10.22 |
0.0984 / 0.1983 |
37.8 % / 99.4 % |
3.60 / 4.96 |
Both arms of each row share a donor ordering and the same three seeds, so the ordering sensitivity above cancels within a row and the comparison is paired – which is why this table reports both arms and the one above reports a level with a caveat.
The answer depends on the outcome, and the first column is what it depends on. Where the treated series’ mean is small next to its own variation – both of the paper’s panels, which are growth rates – forcing \(\alpha = 0\) costs nothing and the simplex carries the fit alone. Where the mean is ten times the variation, as in cigarette packs per capita, the same ablation doubles the scatter off the simplex, takes it to 99 % of a typical weight, and recruits half again as many donors.
The reason is leverage, not feasibility. With \(\sum_j w_j = 1\) and \(w_j \ge 0\) the fitted pre-treatment mean is a convex combination of the donors’ pre-treatment means, so the treated mean is attainable whenever it lies between the smallest and largest of them – and on all three panels it does, at 0.61, 0.32 and 0.25 of the way through the range. Attainable is not free. When the mean is large next to the variation, nearly all of \(\mathbf{w}\)’s freedom goes into hitting the level, and the posterior buys back the freedom to fit the shape by inflating \(\nu\). When the mean is near zero, perturbing the weights barely moves the level, so sum-to-one costs nothing to satisfy.
Two things follow for a reader. A levels outcome – sales, revenue, packs,
visits – is the regime where the intercept matters most, and it is the regime
neither of the paper’s applications occupies, so take the paper’s silence on
the intercept as untested there and not as evidence. And on such a panel a
large relative_deviation may be reporting a level the weights are
struggling to reach, not a mixture whose shape is wrong; demeaned data, which
is what mlsynth feeds the sampler, separates the two.
Hong Kong closes the loop in the other direction. Section 1.1 attributes its need for a relaxation to the treated unit’s level exceeding any convex combination of its donors. Its level is comfortably inside that range, its ablation is null, and its \(\nu\) still runs an order of magnitude above the watch panel’s. What the posterior buys room for there is the shape of the mixture, not its offset.
When to use BVSS – and when not to#
Reach for BVSS when:
The donor pool is large relative to the pre-period (\(N \gtrsim T_0\)). The classical SCM quadratic program has no unique solution; Lasso over-selects; BVSS’s spike-and-slab cleanly returns a sparse posterior on inclusion.
The simplex constraint itself is in question. Hong Kong handover, Basque conflict, China anti-corruption watches – cases where the treated unit’s level may legitimately exceed any convex combination of donors. BVSS’s learned \(\nu\) tells you which regime the data prefers.
You want posterior distributions, not point estimates. The full posterior of the ATT, of each donor’s weight, and of inclusion are returned – useful for downstream uncertainty propagation (e.g. into a policy-evaluation report’s CI reporting).
You want to formalise the “which donors do I trust” decision. Posterior inclusion probabilities replace the practitioner’s eyeball “I’ll keep these states because they look similar” step with a probability statement.
Do not use BVSS when:
Small donor pool with clear pre-fit. With \(N = 8\) states and a tight pre-fit on the canonical SCM, BVSS’s per-pair Gibbs sampler is overkill; the spike-and-slab uncertainty just propagates noise that the data does not actually contain. Use canonical SCM, Two-Step Synthetic Control, or Forward Difference-in-Differences (FDID).
Treated unit is severely outside the donor hull. BVSS’s soft simplex can relax (\(\nu\) learns), but the posterior weights are still anchored to the simplex prior. For the structural outside-hull case, Imperfect Synthetic Controls (ISCM)’s moment- condition framework is identification-aware in a way BVSS is not.
Distribution of the outcome is the object of interest. BVSS targets the mean ATT through a Gaussian likelihood on levels. Distributional questions (Lorenz curves, QTEs, inequality measures) need Distributional Synthetic Control (DSC).
You need speed. MCMC is materially slower than optimisation-based SC. The China-watches application takes ~10 minutes for 1000 iterations on commodity hardware; for large grid searches or batch processing across many policy-evaluation cells, an optimisation-based estimator (canonical SCM, Two-Step Synthetic Control, Forward Difference-in-Differences (FDID)) is the right default.
Outcomes with hard floors or ceilings, counts, or heavy tails. A4’s Gaussian-likelihood / \(\beta\)-min argument breaks. Pre-process (log, difference, Winsorise) before BVSS, or move to a discrete-outcome estimator.
Strong serial correlation in pre-period residuals. The iid-error assumption inflates \(\phi\)’s posterior precision and the inclusion threshold; weights become artificially sharp. First-difference the panel before feeding into BVSS, or use a cycle-decomposing estimator (Synthetic Business Cycle (SBC)).
Treated unit’s outcome is non-stationary. A5 governs the pre-period sample size; the consistency story does not cover unit-root outcomes. First-difference, or move to a stationary-cycle approach.
Continuous or multi-valued treatment. BVSS encodes binary treatment via a single treated-unit indicator. Continuous dose belongs in Continuous-Treatment Synthetic Control (CTSC).
You need a single sparse interpretable weight vector for policy storytelling. BVSS returns posterior expected weights – a Bayesian model average. If the goal is the canonical “California = 0.385 Utah + 0.271 Montana + 0.186 Nevada + …” story, run canonical SCM alongside and report both. The inclusion probabilities from BVSS sit at a different rhetorical altitude.
Core API#
Bayesian Variable Selection with Soft Simplex constraint (BVS-SS).
Implements:
Xu, Y., & Zhou, Q. (2025). “Bayesian Synthetic Control with a Soft Simplex Constraint.” arXiv:2503.06454.
BVS-SS layers a spike-and-slab prior on top of a soft simplex prior on
the donor weights, with the soft-constraint variance tau learned
from the data. Posterior samples are drawn by a Metropolis-within-
Gibbs sampler that jointly updates pairs of inclusion indicators and
the corresponding weights (Lemmas S1, S2 of the paper).
See mlsynth.utils.bvss_helpers for the algorithmic pieces.
- class mlsynth.estimators.bvss.BVSS(config: BVSSConfig | dict)#
Bases:
objectBayesian Synthetic Control with a soft simplex constraint.
- Parameters:
config (BVSSConfig or dict) – Configuration object. See
mlsynth.config_models.BVSSConfig.- Returns:
BVSSResults – Posterior samples of
\mu, \phi, \tau, the implied 0/1 inclusion indicators, the posterior-mean counterfactual with credible bands, and the ATT mean + credible interval.
- fit() BVSSResults#
Run the BVS-SS Gibbs sampler and assemble results.
Configuration#
- class mlsynth.config_models.BVSSConfig(*, df: ~pandas.DataFrame, outcome: str, treat: str, unitid: str, time: str, display_graphs: bool = False, save: bool | str = False, counterfactual_color: ~typing.List[str] = <factory>, treated_color: str = 'black', plot: ~mlsynth.config_models.PlotConfig = <factory>, n_iter: ~typing.Annotated[int, ~annotated_types.Ge(ge=10)] = 2000, burn_in: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)] = 1000, kappa1: ~typing.Annotated[float, ~annotated_types.Gt(gt=0)] = 1.0, kappa2: ~typing.Annotated[float, ~annotated_types.Gt(gt=0)] = 1.0, theta: ~typing.Annotated[float, ~annotated_types.Gt(gt=0.0), ~annotated_types.Lt(lt=1.0)] = 0.25, tau_a: ~typing.Annotated[float, ~annotated_types.Gt(gt=0)] = 0.01, tau_b: ~typing.Annotated[float, ~annotated_types.Gt(gt=0)] = 0.1, n_tau: ~typing.Annotated[int, ~annotated_types.Ge(ge=1)] = 11, tau_min: ~typing.Annotated[float, ~annotated_types.Gt(gt=0)] = 1e-06, ci_alpha: ~typing.Annotated[float, ~annotated_types.Gt(gt=0.0), ~annotated_types.Lt(lt=1.0)] = 0.05, init_phi: ~typing.Annotated[float, ~annotated_types.Gt(gt=0)] = 0.8, init_tau: ~typing.Annotated[float, ~annotated_types.Gt(gt=0)] = 1.0, init_mu: ~typing.List[float] | None = None, verbose: bool = False, seed: int | None = None)#
Configuration for the Bayesian Synthetic Control with Soft Simplex (BVS-SS).
Implements:
Xu, Y., & Zhou, Q. (2025). “Bayesian Synthetic Control with a Soft Simplex Constraint.” arXiv:2503.06454.
- Parameters:
n_iter (int) – Total Gibbs iterations (including burn-in).
burn_in (int) – Number of warm-up iterations discarded before reporting.
kappa1, kappa2 (float) – Gamma hyperparameters for the prior on the observation precision phi. Paper Section 5.1 uses kappa1=kappa2=1.
theta (float) – Bernoulli prior inclusion probability per donor. Paper’s empirical Section 6 uses theta in 0.2–0.25.
tau_a, tau_b (float) – Gamma-prior shape (a1) and rate (a2) for the soft-constraint variance tau. Paper Section 5.1 uses (0.01, 0.1).
n_tau (int) – Number of MH steps for tau per outer iteration.
tau_min (float) – Numerical floor on tau; proposals below are reflected.
ci_alpha (float) – Two-sided significance level for credible intervals (default 0.05 gives 95% bands).
init_phi, init_tau (float) – Initial values for phi and tau.
init_mu (list, optional) – Initial weight vector of length N. Defaults to the uniform simplex mu_i = 1 / N.
display_graphs (bool) – Display the observed-vs-counterfactual plot after the fit.
verbose (bool) – Show a tqdm progress bar during MCMC.
seed (int, optional) – Seed for the numpy.random.Generator used inside the sampler.
- model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
Helper Modules#
Data preparation for BVS-SS.
Wraps mlsynth.utils.datautils.dataprep() and demeans the
pre-treatment block before passing it to the Gibbs sampler. The
post-treatment donor block is demeaned using the pre-treatment column
means so that out-of-sample counterfactual paths are computed in the
same centered coordinate system as the sampler.
- mlsynth.utils.bvss_helpers.setup.prepare_bvss_inputs(df: DataFrame, outcome: str, unitid: str, time: str, treat: str) BVSSInputs#
Pivot panel data and demean to match the BVS-SS sampler’s contract.
- Parameters:
df (pd.DataFrame) – Long balanced panel data.
outcome, unitid, time, treat (str) – Column names identifying the outcome, units, time periods, and the binary treatment indicator.
- Returns:
BVSSInputs
Math primitives for the BVS-SS Metropolis-within-Gibbs sampler.
Implements Eqs. (4) and (5) of Xu & Zhou (2025), “Bayesian Synthetic Control with a Soft Simplex Constraint” (arXiv:2503.06454), plus the log-determinant of the model-complexity factor \(A_\alpha(\gamma, \tau)\) when \(\alpha = 1\) (Lemma S2).
All functions are pure numpy and side-effect free.
- mlsynth.utils.bvss_helpers.posterior.AM(gamma_vec: ndarray, tau: float, theta: float, Gram: ndarray, N: int) float#
Log of the model-complexity factor for a given inclusion vector.
Computes the part of \(\log p(\gamma, \mu_\gamma)\) that depends on the structure of
gammafor the \(\alpha = 1\) case (Lemma S2 + Eq. (2) of the paper):\[\log A_1(\gamma, \tau) = |\gamma| \log \theta + (N - |\gamma|) \log (1 - \theta) + \log (|\gamma| - 1)! - \tfrac{1}{2} \log \det V_{\gamma, \tau}.\]The \(-\tfrac{|\gamma|}{2} \log \tau\) term is handled separately inside
loglike().
- mlsynth.utils.bvss_helpers.posterior.RSS(gamma_vec: ndarray, tau: float, z: ndarray, X: ndarray, Gram: ndarray) float#
Quadratic form
z^T \Sigma_{\gamma, \tau} z.Uses
\[\Sigma_{\gamma, \tau} = I - X_\gamma V_{\gamma, \tau}^{-1} X_\gamma^T,\]so that
\[z^T \Sigma_{\gamma, \tau} z = z^T z - (X_\gamma^T z)^T V^{-1} (X_\gamma^T z).\]
- mlsynth.utils.bvss_helpers.posterior.RSS2(gamma_vec: ndarray, tau: float, z1: ndarray, z2: ndarray, X: ndarray, Gram: ndarray) float#
Bilinear form
z_1^T \Sigma_{\gamma, \tau} z_2.The symmetric counterpart of
RSS(), used inside the pair Gibbs step to evaluate the cross term that determines \(\beta_{i,j}\) (Lemma S1 / Eq. S3 of the paper).
- mlsynth.utils.bvss_helpers.posterior.VM(gamma_vec: ndarray, tau: float, Gram: ndarray) ndarray#
Posterior covariance matrix for the selected predictors.
Implements Eq. (5):
\[V_{\gamma, \tau} = X_\gamma^T X_\gamma + \tau^{-1} I.\]- Parameters:
gamma_vec (np.ndarray) – Length-
Nbinary inclusion indicator.tau (float) – Prior precision parameter for the included coefficients.
Gram (np.ndarray) – Pre-computed Gram matrix
X^T X.
- Returns:
np.ndarray – Either
V_{\gamma, \tau}of shape(|gamma|, |gamma|)or the scalar fallback[[1/tau]]when no predictors are selected.
- mlsynth.utils.bvss_helpers.posterior.loglike(gamma_vec: ndarray, tau: float, mu: ndarray, phi: float, Y: ndarray, X: ndarray, Gram: ndarray) float#
Log of the marginal likelihood
p(y | \gamma, \mu_\gamma, \tau, \phi).Implements Eq. (4) of the paper:
\[\log p(y \mid \gamma, \mu_\gamma, \tau, \phi) = \tfrac{M}{2} \log \phi - \tfrac{|\gamma|}{2} \log \tau - \tfrac{1}{2} \log \det V_{\gamma, \tau} - \tfrac{\phi}{2} (y - X_\gamma \mu_\gamma)^T \Sigma_{\gamma, \tau} (y - X_\gamma \mu_\gamma).\]
Joint Gibbs update of (gamma_i, gamma_j, mu_i, mu_j) for one donor pair.
Implements the two-coordinate Gibbs move of Xu & Zhou (2025), Section 3.2 and
Lemmas 1-2. Given the other entries of \mu fixed, the four-case conditional
distribution of the inclusion pair \((\gamma_i, \gamma_j)\) is:
(0, 0): infeasible if
s = 1 - \sum_{k\neq i,j} \mu_k > 0.(1, 0): forces
\mu_i = s, \mu_j = 0.(0, 1): forces
\mu_i = 0, \mu_j = s.(1, 1): draws
\mu_i = ufrom a truncated normal \(N_{(0, s)}(\beta_{i,j}, (\phi \Lambda_{i,j})^{-1})\) and sets\mu_j = s - u.
When s = 0 the simplex constraint already pins \mu_i = \mu_j = 0 and no
draw is needed.
Each case is scored at its own inclusion vector – Eq. (11)’s \(\gamma^i, \gamma^j, \gamma^{ij}\), which are three different sets of two different cardinalities. Lemma 2 indexes both the complexity factor \(A(\gamma, \tau)\) and the projector \(\Sigma_{\gamma, \tau}\) by the state’s own vector.
Only the pair’s three inclusion vectors change between the four cases, so each
of the three posterior covariances \(V_{\gamma, \tau}\) is built once per
pair and shared by the complexity factor and the quadratic forms that need it.
mlsynth/tests/test_bvss.py pins the result of the sharing against the
unshared primitives, draw for draw.
Metropolis-Hastings update for the soft-constraint variance tau.
Implements the log-random-walk proposal of Xu & Zhou (2025), Eq. (S1):
log tau^* = log tau + N(0, 1),
with a reflective barrier at log tau_min so the chain never drops
below a numerical floor. The acceptance probability comes from
- rho = min{1,
p(y | mu, tau^*, phi) p(tau^*) / [p(y | mu, tau, phi) p(tau)] * (tau^* / tau)},
where the Jacobian factor \tau^* / \tau arises from the log-RW
proposal. The (tau prior) is Gamma(a, b).
- mlsynth.utils.bvss_helpers.mh.MH_tau(tau: float, gamma_vec: ndarray, mu: ndarray, phi: float, Y: ndarray, X: ndarray, Gram: ndarray, a: float = 0.01, b: float = 0.1, tau_min: float = 1e-06, nrep: int = 11, rng: Generator | None = None) float#
Run
nrepMH steps for\tauand return the final draw.- Parameters:
tau (float) – Current value of tau.
gamma_vec (np.ndarray) – Current inclusion indicator.
mu (np.ndarray) – Current weight vector.
phi (float) – Current observation-noise precision.
Y, X, Gram (np.ndarray) – Response, predictor matrix, and Gram matrix.
a, b (float) – Gamma-prior shape and rate parameters for tau.
tau_min (float) – Numerical floor; proposals below are reflected.
nrep (int) – Number of MH steps per call (paper’s
n_\tau).rng (numpy.random.Generator, optional) – Used for both proposal noise and accept/reject draws. Falls back to
numpy.randomwhenNone.
- Returns:
float – tau value after the final (
nrep-th) step.
Outer Metropolis-within-Gibbs loop for BVS-SS.
Implements Algorithm 1 of Xu & Zhou (2025), arXiv:2503.06454. The sweep order per outer iteration:
For every donor pair
(i, j)withi < j: jointly update(\gamma_i, \gamma_j, \mu_i, \mu_j)via the closed-form four-case Gibbs draw (Lemma S2 + Lemma S1).Sample
\phifrom its full conditionalGamma((M+\kappa_1)/2, (\kappa_2 + RSS) / 2)(Eq. (6)).Run
n_\tauMH steps for\tauagainst its target conditional (Eq. (S1)).
The w Gibbs step (Eq. (7)) is not drawn in this implementation —
counterfactuals are computed directly from \mu samples, matching
the reference script’s behavior and reducing posterior variance.
- mlsynth.utils.bvss_helpers.sampler.gibbs_BVS(Y: ndarray, X: ndarray, Gram: ndarray, M: int, N: int, size: int, kappa1: float = 1.0, kappa2: float = 1.0, theta: float = 0.25, tau_min: float = 1e-06, a: float = 0.01, b: float = 0.1, n_tau: int = 11, init_mu: ndarray | None = None, init_phi: float = 0.8, init_tau: float = 1.0, verbose: bool = False, rng: Generator | None = None) dict#
Run
sizeMCMC iterations targeting the BVS-SS posterior.- Parameters:
Y (np.ndarray) – Demeaned outcome vector of length
M.X (np.ndarray) – Demeaned predictor matrix of shape
(M, N).Gram (np.ndarray) –
X.T @ X.M (int) – Number of observations (pre-treatment time periods).
N (int) – Number of donor predictors.
size (int) – Total number of MCMC iterations (including burn-in).
kappa1, kappa2 (float) – Gamma hyperparameters for the prior on
\phi.theta (float) – Prior inclusion probability for each predictor.
tau_min (float) – Numerical floor for
\tau.a, b (float) – Gamma-prior shape / rate for
\tau.n_tau (int) – Number of MH steps for
\tauper outer iteration.init_mu (np.ndarray, optional) – Initial weight vector. Defaults to the uniform-simplex
\mu = 1 / N.init_phi, init_tau (float) – Initial values for the precision parameters.
verbose (bool) – Show a tqdm progress bar.
rng (numpy.random.Generator, optional) – Random number generator for reproducibility. Falls back to
numpy.randomand the globalscipy.statsstate whenNone.
- Returns:
dict – Mapping with keys:
musample:(N, size)posterior samples of\mu.phisample: length-sizeposterior samples of\phi.tausample: length-sizeposterior samples of\tau.gammasample:(N, size)0/1 inclusion indicators implied by\mu.
Counterfactual paths, credible bands, and ATT inference for BVS-SS.
Given posterior samples \mu^{(t)} from the Gibbs sampler, the
counterfactual treated outcome at every period is:
Y_hat^{(0)}_t = X_demean_t \mu^{(t)} + mean_Y,
where mean_Y is the pre-treatment mean of the treated outcome (the
sampler operates on demeaned data; we add the mean back to recover the
original outcome scale).
The post-treatment ATT for each draw is:
ATT^{(t)} = (1 / T_post) \sum_{t > T_0}
(Y^{(1)}_t - Y_hat^{(0), (t)}_t)
= (1 / T_post) \sum_{t > T_0}
((Y^{(1)}_t - mean_Y) - X_demean_t \mu^{(t)}).
- mlsynth.utils.bvss_helpers.inference.compute_inference(inputs: BVSSInputs, mu_samples: ndarray, ci_alpha: float = 0.05) BVSSInference#
Assemble
BVSSInferencefrom posterior\musamples.- Parameters:
inputs (BVSSInputs) – Demeaned panel inputs.
mu_samples (np.ndarray) – Shape
(N, n_samples)posterior samples of\muafter burn-in.ci_alpha (float) – Two-sided significance level. Credible bands are at the
ci_alpha / 2and1 - ci_alpha / 2percentiles.
Observed vs counterfactual plot for BVS-SS, with posterior CI band.
- mlsynth.utils.bvss_helpers.plotter.plot_bvss(results: BVSSResults, title: str | None = None) None#
Plot observed series, BVS-SS counterfactual, and pointwise CI band.
Mirrors the layout the BVS-SS paper uses in its empirical figures: one continuous black series for the observed outcome, a dashed blue posterior-mean counterfactual, a shaded CI band, and a vertical line at
T_0.
Note
BVSS.fit() returns an EffectResult on the
standardized two-family contract: res.att (posterior mean ATT) /
res.att_ci (credible interval) / res.counterfactual (posterior mean)
/ res.gap / res.donor_weights (posterior mean weights) /
res.pre_rmse resolve through the standardized sub-models. The full
Bayesian detail – the MCMC posterior, per-draw ATT samples, and pointwise
counterfactual bands – is on res.inference_detail / res.posterior
(the bare res.inference slot is reserved for the standardized ATT-level
InferenceResults). res.simplex carries
the posterior’s verdict on the soft simplex; see Reading the simplex
verdict.
Structured containers for the BVS-SS estimator.
Implements containers for the BVS-SS pipeline of Xu & Zhou (2025), arXiv:2503.06454.
- class mlsynth.utils.bvss_helpers.structures.BVSSInference(att_mean: float, att_ci_lower: float, att_ci_upper: float, att_samples: ndarray, ci_alpha: float, counterfactual_mean: ndarray, counterfactual_lower: ndarray, counterfactual_upper: ndarray)#
Point estimate plus credible interval for the ATT.
- Parameters:
att_mean (float) – Posterior mean ATT over the post-treatment horizon.
np.nanwhen no post window exists.att_ci_lower, att_ci_upper (float) – Credible interval bounds at level
1 - ci_alpha.att_samples (np.ndarray) – Length-
n_samplesper-MCMC-draw ATT.ci_alpha (float) – Significance level used to build the interval.
counterfactual_mean (np.ndarray) – Length-
Tposterior-mean counterfactual (in original outcome units, not demeaned).counterfactual_lower, counterfactual_upper (np.ndarray) – Length-
Tpointwise credible bands.
- att_samples: ndarray#
- counterfactual_lower: ndarray#
- counterfactual_mean: ndarray#
- counterfactual_upper: ndarray#
- class mlsynth.utils.bvss_helpers.structures.BVSSInputs(Y_pre_demean: ndarray, X_pre_demean: ndarray, X_post_demean: ndarray | None, Gram: ndarray, mean_Y: float, mean_X: ndarray, T0: int, T: int, N: int, treated_unit_name: str, donor_names: Sequence, time_labels: ndarray, y_target: ndarray)#
Demeaned panel data fed into the Gibbs sampler.
- Parameters:
Y_pre_demean (np.ndarray) – Length-
T0demeaned treated pre-treatment outcome.X_pre_demean (np.ndarray) – Shape
(T0, N)demeaned donor matrix over the pre-treatment window.X_post_demean (np.ndarray or None) – Shape
(T_post, N)demeaned donor matrix over the post window (uses the pre-treatment column means).Noneif there is no post period.Gram (np.ndarray) – Pre-computed
X_pre_demean.T @ X_pre_demean.mean_Y (float) – Pre-treatment mean of the treated outcome, used to undo the demeaning when forming counterfactual paths.
mean_X (np.ndarray) – Length-
Nper-donor pre-treatment means.T0 (int) – Number of pre-treatment periods.
T (int) – Total number of periods.
N (int) – Number of donor units.
treated_unit_name (str)
donor_names (Sequence)
time_labels (np.ndarray)
y_target (np.ndarray) – Original (un-demeaned) treated outcome over all
Tperiods.
- Gram: ndarray#
- X_pre_demean: ndarray#
- Y_pre_demean: ndarray#
- mean_X: ndarray#
- time_labels: ndarray#
- y_target: ndarray#
- class mlsynth.utils.bvss_helpers.structures.BVSSPosterior(mu: ndarray, phi: ndarray, tau: ndarray, gamma: ndarray, burn_in: int, n_iter: int)#
MCMC samples drawn by the BVS-SS Gibbs sampler.
- Parameters:
mu (np.ndarray) – Shape
(N, n_samples)posterior samples of\mu(after burn-in).phi (np.ndarray) – Length-
n_samplesposterior samples of\phi.tau (np.ndarray) – Length-
n_samplesposterior samples of\tau.gamma (np.ndarray) – Shape
(N, n_samples)0/1 inclusion indicators implied bymu.burn_in (int) – Number of warm-up iterations dropped before this slice.
n_iter (int) – Total iterations the chain ran for (including burn-in).
- gamma: ndarray#
- mu: ndarray#
- phi: ndarray#
- tau: ndarray#
- class mlsynth.utils.bvss_helpers.structures.BVSSResults(*, effects: EffectsResults | None = None, fit_diagnostics: FitDiagnosticsResults | None = None, time_series: TimeSeriesResults | None = None, weights: WeightsResults | None = None, inference: InferenceResults | None = None, method_details: MethodDetailsResults | None = None, sub_method_results: Dict[str, Any] | None = None, additional_outputs: Dict[str, Any] | None = None, raw_results: Dict[str, Any] | None = None, execution_summary: Dict[str, Any] | None = None, plot_config: PlotConfig | None = None, inputs: BVSSInputs, posterior: BVSSPosterior, inference_detail: BVSSInference, inclusion_probs: dict, weight_means: dict, simplex: BVSSSimplexDiagnostics)#
Public
BVSS.fit()return container.An
EffectResult(the observational report): it populates the standardized sub-models so the flat accessors (att/att_ci/counterfactual/gap/donor_weights/pre_rmse) resolve through the base contract.attis the posterior mean ATT andatt_ciits credible interval;donor_weightsare the posterior mean weights. The full Bayesian detail – the MCMC posterior, the per-draw ATT samples, the pointwise counterfactual bands, and the inclusion probabilities – stays in the typed fields below.- Parameters:
inputs (BVSSInputs)
posterior (BVSSPosterior)
inference_detail (BVSSInference) – Posterior ATT / counterfactual bands (was
inferencebefore the contract migration; the standardizedinferenceslot now holds the ATT-levelInferenceResults).inclusion_probs (dict) –
donor_label -> P(\gamma_i = 1 | y)posterior inclusion frequencies over the post burn-in samples.weight_means (dict) –
donor_label -> E[\mu_i | y]posterior mean weights.simplex (BVSSSimplexDiagnostics) – What the posterior says about the simplex constraint the model softens.
- inference_detail: BVSSInference#
- inputs: BVSSInputs#
- model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True, 'json_encoders': {<class 'numpy.ndarray'>: <function BaseEstimatorResults.Config.<lambda>>}}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- posterior: BVSSPosterior#
- simplex: BVSSSimplexDiagnostics#
- class mlsynth.utils.bvss_helpers.structures.BVSSSimplexDiagnostics(tau_mean: float, tau_median: float, tau_q025: float, tau_q975: float, deviation_scale: float, weight_sum_sd: float, relative_deviation: float, model_size_mean: float)#
How far the data let the weights drift off the simplex.
Equation (2) of Xu and Zhou (2025) gives the actual weights
\[\mathbf{w}_\gamma \mid \gamma, \boldsymbol{\mu}_\gamma, \tau, \phi \sim N(\boldsymbol{\mu}_\gamma, (\tau / \phi) I),\]so they are centred on a point of the simplex and scattered around it with standard deviation \(\sqrt{\tau / \phi}\) per coordinate. Section 2.1 reads that scatter as the data’s verdict on the constraint: a posterior for \(\tau\) concentrating near zero says the simplex is appropriate, and one staying away from zero says it is violated.
Every field is analytic in the draws of \(\tau\), \(\phi\) and \(|\gamma|\), so none of it depends on how the counterfactual is built – which matters, because that construction is an open question recorded in
docs/bvss.rst.- Parameters:
tau_mean, tau_median, tau_q025, tau_q975 (float) – Posterior summaries of \(\tau\).
deviation_scale (float) – \(E[\sqrt{\tau / \phi}]\), the per-coordinate standard deviation of a weight about its simplex centre, in weight units.
weight_sum_sd (float) – \(E[\sqrt{|\gamma| \tau / \phi}]\). The coordinates are independent given the parameters, so the variances add and the sum of the weights departs from one on this scale.
relative_deviation (float) –
deviation_scaleagainst a typical weight \(1 / |\gamma|\). A scatter of 0.05 means one thing across three donors and another across thirty, and this is the comparable number.model_size_mean (float) – Posterior mean \(|\gamma|\), carried so the two scales above can be read without a second pass over the draws.
- mlsynth.utils.bvss_helpers.structures.simplex_diagnostics(posterior: BVSSPosterior) BVSSSimplexDiagnostics#
Summarise the posterior’s verdict on the simplex constraint.
- Parameters:
posterior (BVSSPosterior) – Post burn-in draws of
mu,phiandtau.- Returns:
BVSSSimplexDiagnostics
Example#
A minimal end-to-end run on the China anti-corruption / luxury-watch panel (the same outcome series the empirical replication below benchmarks against). With the default priors and sampler settings, the BVSS API is just five fields plus a display toggle:
import pandas as pd
from mlsynth import BVSS
url = "https://raw.githubusercontent.com/jgreathouse9/mlsynth/refs/heads/main/basedata/china_watches_long.csv"
data = pd.read_csv(url)
config = {
"df": data,
"outcome": "y",
"unitid": "unit",
"time": "time",
"treat": "treat",
"display_graphs": True,
}
results = BVSS(config).fit()
# ------------------------------------------------------------------
# Headline ATT
# ------------------------------------------------------------------
print(f"ATT posterior mean: {results.inference_detail.att_mean:.4f}")
print(f"95% credible interval: "
f"[{results.inference_detail.att_ci_lower:.4f}, "
f"{results.inference_detail.att_ci_upper:.4f}]")
# ------------------------------------------------------------------
# Donor selection: posterior inclusion probabilities and weight means
# ------------------------------------------------------------------
for donor in sorted(results.weight_means,
key=lambda k: -results.weight_means[k])[:5]:
w_bar = results.weight_means[donor]
p_in = results.inclusion_probs[donor]
print(f" {donor:25s}: weight = {w_bar:.4f}, P(included) = {p_in:.3f}")
# ------------------------------------------------------------------
# Soft-simplex diagnostic: what the posterior says about the constraint
# ------------------------------------------------------------------
s = results.simplex
print(f"\nposterior mean of tau: {s.tau_mean:.4f}")
print(f" 95% credible set: [{s.tau_q025:.4f}, {s.tau_q975:.4f}]")
print(f"off-simplex sd per weight: {s.deviation_scale:.4f}")
print(f" against a typical weight: {s.relative_deviation:.1%}")
print(f"sd of sum(w) about one: {s.weight_sum_sd:.4f}")
print(f"posterior mean model size: {s.model_size_mean:.2f}")
print(f"posterior mean of phi: {results.posterior.phi.mean():.4f}")
# A small relative_deviation means the hard simplex would have cost little;
# a large one means the fit left the simplex to reach the treated series.
# ------------------------------------------------------------------
# Counterfactual path and per-period bands (in original outcome units)
# ------------------------------------------------------------------
results.inference_detail.counterfactual_mean # shape (T,)
results.inference_detail.counterfactual_lower # shape (T,)
results.inference_detail.counterfactual_upper # shape (T,)
# ------------------------------------------------------------------
# Raw MCMC samples for downstream analysis (after burn-in)
# ------------------------------------------------------------------
results.posterior.mu # (N, n_post_samples)
results.posterior.phi # (n_post_samples,)
results.posterior.tau # (n_post_samples,)
results.posterior.gamma # (N, n_post_samples) 0/1 inclusion indicators
Verification#
Empirical replication against the authors’ published numbers (Path
A). Xu & Zhou’s Section 6.2 [BVSS] benchmarks BVS-SS on the China
anti-corruption case: the Eight-Point policy announced in January 2013
sharply depressed luxury-watch imports, an outcome the paper measures
through the monthly growth rate of the customs category “watches with
case of, or clad with, precious metal” (from the fdPDA R package
of Shi & Huang 2023). The donor pool is the remaining \(N = 87\)
HS commodity categories over Feb 2010 - Dec 2015. mlsynth.BVSS
on the same panel reproduces the paper’s Table 3 headline values
essentially exactly.
Path A: Shi & Huang (2023) luxury-watch imports#
The replication panel (1 treated category + 87 donor categories
\(\times\) 71 months, \(T_0 = 35\)) is hosted at
china_import_final.csv in
jgreathouse9/RepACCFDID.
mlsynth.BVSS with the paper’s published hyperparameters
(\(\kappa_1 = \kappa_2 = 1\), \(a_1 = 0.01\), \(a_2 =
0.1\), \(\alpha = 1\), \(\theta = 0.2\), 1000 iterations, 500
discarded as burn-in) reproduces the published Table 3 values:
import pandas as pd
import numpy as np
from mlsynth import BVSS
url = ("https://raw.githubusercontent.com/jgreathouse9/RepACCFDID/"
"refs/heads/main/china_import_final.csv")
raw = pd.read_csv(url).rename(columns={"Unnamed: 0": "yyyymm"})
T = len(raw)
T0 = int((raw["yyyymm"].astype(int) < 201301).sum()) # = 35
donor_cols = [c for c in raw.columns if c not in ("yyyymm", "treated")]
rows = [{"unit": "watches", "time": t, "y": float(raw["treated"].iloc[t]),
"treat": int(t >= T0)} for t in range(T)]
for c in donor_cols:
rows += [{"unit": c, "time": t, "y": float(raw[c].iloc[t]),
"treat": 0} for t in range(T)]
df = pd.DataFrame(rows)
res = BVSS({
"df": df, "outcome": "y", "treat": "treat",
"unitid": "unit", "time": "time",
"n_iter": 1000, "burn_in": 500,
"kappa1": 1.0, "kappa2": 1.0, "theta": 0.2,
"tau_a": 0.01, "tau_b": 0.1, "ci_alpha": 0.05,
"init_phi": 1.0, "init_tau": 1.0, "seed": 0,
"display_graphs": False,
}).fit()
tau = res.posterior.tau
phi = res.posterior.phi
gamma_count = res.posterior.gamma.sum(axis=0)
print(f"ATT = {res.inference_detail.att_mean:+.3f} "
f"({res.inference_detail.att_ci_lower:+.3f}, "
f"{res.inference_detail.att_ci_upper:+.3f})")
print(f"tau = {tau.mean():.3f}")
print(f"phi = {phi.mean():.2f}")
print(f"|gamma|= {gamma_count.mean():.2f}")
prints (one chain at seed=0, after ~10 minutes on commodity
hardware):
Statistic |
Published (Xu & Zhou 2025, Table 3) |
Replicated here |
|---|---|---|
ATT (mean) |
\(-0.021\) |
\(-0.020\) |
ATT (95% credible interval) |
\((-0.032,\ -0.008)\) |
\((-0.033,\ -0.003)\) |
\(\phi\) (posterior mean) |
\(20.86\) |
\(19.94\) |
\(\phi\) (95% CI) |
\((12.22,\ 32.76)\) |
\((11.41,\ 31.68)\) |
\(\nu\) (posterior mean) |
\(0.069\) |
\(0.030\) |
\(|\gamma|\) (posterior mean) |
\(5.09\) |
\(8.89\) |
The headline ATT matches to three decimals (\(\widehat{\tau} = -0.020\) here vs. \(-0.021\) in the paper) and the 95% credible interval lines up closely with the published \((-0.032,\ -0.008)\). The observation-noise precision \(\phi\) is reproduced essentially exactly (\(19.94\) vs. \(20.86\), well within the published interval). The mild discrepancies in \(\nu\) and \(|\gamma|\) are MCMC-seed sensitive: a different RNG draw shifts the posterior of the soft-simplex tightness parameter without moving the headline ATT. The ordering – “the data supports the simplex constraint (\(\nu\) near zero) and the relevant donor set is small (a handful of commodity categories)” – carries through to the same substantive conclusion the paper reports: a statistically meaningful negative ATT on luxury-watch imports after the anti-corruption announcement, with posterior credibility that excludes zero.
Cross-validation against the authors’ own sampler. Beyond matching the
published table, benchmarks/cases/bvss_watches.py checks mlsynth’s BVSS
directly against Xu & Zhou’s own two-coordinate Gibbs code (taken verbatim from
their fsPDA replication script) on the same anti-corruption panel. Because the
sampler is stochastic, the check has two layers. The deterministic engine –
the posterior covariance log-determinant, the RSS / RSS2 quadratic and
bilinear forms, the model-complexity term and the marginal log-likelihood – is
reproduced value for value on a fixed \((\gamma, \tau, \mu, \phi)\) to about
\(10^{-9}\), so both implementations draw from the identical target. The
seeded posterior-mean ATT then agrees within Monte-Carlo error
(\(-0.021\) here vs. \(-0.021\) from the R sampler, independent RNG
streams), with a negative credible set and a sparse selected model on both
sides. The live-captured reference is under
benchmarks/reference/bvss_watches/.
Three properties of that credible set are asserted: that it brackets the point estimate, that it is entirely negative as the R’s is, and that its width is within an order of magnitude of the R’s. The first two are exact. The third carries a deliberately wide tolerance, because the width is a 95 % quantile of 25 retained draws and ranges over 0.48 to 1.07 times the R’s across eight seeds at the benchmark’s chain length – 0.67 to 1.08 even at 400 iterations. A tolerance loose enough never to flake asserts nothing about agreement, so the ratio is labelled in the case as a guard against order-of-magnitude breakage and the two shape properties carry the content.
Dependencies#
By design the BVS-SS implementation in mlsynth avoids the
heavier probabilistic-programming stack. The sampler depends only on
numpy and the following modules from scipy:
scipy.linalg—solveanddetscipy.special—factorialscipy.stats—norm,truncnorm,gamma
The optional tqdm progress bar is imported lazily and only when
verbose=True is passed.