BayesianDoubleML MCMC example

begin
    using BayesianDoubleML
    using StableRNGs
end

Data generation

Let's generate data as per Section 6 DiTraglia and Liu (2025).

begin
    # Define parameters
    n = 200
    p = 100
    alpha_true = 2.0

    rng = StableRNG(42)

    # Generate data as DataFrame
    df = make_plr_DTL2025(n, p, 2.0; alpha = alpha_true, rng = rng)
end;

Model setup

We then define the BDMLModel, using the hierarchical model (BDML-Hier) from the paper:

As per Section 6 of the paper, the BDML-Hier model "allows different standard deviations in the normal shrinkage priors for \(\delta\) and \(\gamma\) ... with a hierarchical prior that places independent Inverse-Gamma(2, 2) hyper-priors on \(\sigma^2_\delta\) and \(\sigma^2_\gamma\)."

model = BDMLModel(df, :y, :d; model_type = :hier)
BDMLHierarchicalModel (not fitted)
  Observations: 200
  Covariates: 100

Model fitting

We then solve the inference problem via MCMC, using the No-U-Turn Sampler (NUTS), as in the paper:

fit!(
    model,
    MCMCMethod(:nuts),
    n_chains = 8,
    n_samples = 400
)

Model results

begin
    summary(model)
    coeftable(model)
end
Bayesian Double ML Coefficient Table
======================================================================
Parameter: α (treatment effect)
Model type: hier
Inference method: MCMC
Credible interval level: 95.0% (HPD)
Number of posterior samples: 3200

  Parameter     Estimate   Std. Error         MCSE      P-value
  ---------     --------   ----------         ----      -------
  α               1.9246       0.1958       0.0015       0.0000

HPD Credible Intervals:
  α: [1.5353, 2.2985]

Diagnostics:
  Effective Sample Size (ESS): 1875.7