# Divergent transitions with the regularized horseshoe

**URL:** <https://discourse.mc-stan.org/t/divergent-transitions-with-the-regularized-horseshoe/29455>\
**Category:** Modeling\
**Created:** [November 13, 2022, 10:00pm UTC](https://discourse.mc-stan.org/t/divergent-transitions-with-the-regularized-horseshoe/29455 "2022-11-13T22:00:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dkaplan](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/dkaplan/32/13835_2.png) [@dkaplan](https://discourse.mc-stan.org/u/dkaplan)\
**Post date:** [November 13, 2022, 10:00pm UTC](https://discourse.mc-stan.org/t/divergent-transitions-with-the-regularized-horseshoe/29455/1 "2022-11-13T22:00:15Z")

</div>

Hi all,

I’m working on the regularized horseshoe and it is throwing about 30 divergent transitions. The effective sample sizes and rhats for all parameters are fine. The regression has 10 predictors and n is 4000. I realize this is not the optimal situation to demonstrate the regularized horseshoe, but I am still getting a tiny bit of additional shrinkage in the estimates compared to the horseshoe. The code is as follows.

```nohighlight
modelString = "
data {
  int <lower=1> n; // number of observations
  int <lower=1> p; // number of predictors
  real readscore[n]; // outcome
  matrix[n,p] X; // inputs

}

transformed data {
  real p0 = 5;
 // real slab_df = 4;
 // real half_slab_df = 0.5 * slab_df;  
  
}

parameters {
  vector[p] beta;
  vector<lower=0>[p] lambda;
  real<lower=0> c2;
  real<lower=0> tau;
  real alpha;
  real<lower=0> sigma;

}

transformed parameters {
  real tau0 = (p0 / (p - p0)) * (sigma / sqrt(1.0 * n));
  vector[p] lambda_tilde =
     sqrt(c2) * lambda ./ sqrt(c2 + square(tau) * square(lambda));
}
 
model {
  beta ~ normal(0, tau * lambda_tilde);
  lambda ~ cauchy(0, 1);
  c2 ~ inv_gamma(2, 8); 
  tau ~ cauchy(0, tau0);
  
  alpha ~ normal(0, 2);
  sigma ~ cauchy(0, 1);
  
  readscore ~ normal(X * beta + alpha, sigma);

}

// For posterior predictive checking and loo cross-validation
generated quantities {
  vector[n] readscore_rep;
  vector[n] log_lik;
  for (i in 1:n) {
  readscore_rep[i] = normal_rng(alpha + X[i,:] * beta, sigma);
  log_lik[i] = normal_lpdf(readscore[i] | alpha + X[i,:] * beta, sigma);
}
  }

"

```

The code is a slight modification of that given in Betancourt (2018) where instead of specifying the slab scale and slab df, I’m giving c^2 an inverse-gamma (2,8) prior as per a suggestion in Piironen and Vehtari (2017). I have tried the Betancourt code directly and again, the rhats and n\_eff values look fine, but it is throwing around the same number of divergent transition warnings. Any thoughts?

Thanks in advance,

David

---

<div class="post-metadata">

**Author:** ![betanalpha](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/betanalpha/32/4_2.png) [@betanalpha](https://discourse.mc-stan.org/u/betanalpha)\
**Post date:** [December 21, 2022, 9:46pm UTC](https://discourse.mc-stan.org/t/divergent-transitions-with-the-regularized-horseshoe/29455/2 "2022-12-21T21:46:44Z")

</div>

It’s pretty hard to _not_ get a terrible posterior geometry with the horseshoe model. For extensive discussion into why, including experiments and possible alternatives, see [Sparsity Blues](https://betanalpha.github.io/assets/case_studies/modeling_sparsity.html).
