# Horseshoe prior error in rstan

**URL:** <https://discourse.mc-stan.org/t/horseshoe-prior-error-in-rstan/14565>\
**Category:** Modeling\
**Created:** [April 23, 2020, 8:03pm UTC](https://discourse.mc-stan.org/t/horseshoe-prior-error-in-rstan/14565 "2020-04-23T20:03:06Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Se\_Yoon\_Lee](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/se_yoon_lee/32/7809_2.png) [@Se\_Yoon\_Lee](https://discourse.mc-stan.org/u/Se_Yoon_Lee)\
**Post date:** [April 23, 2020, 8:03pm UTC](https://discourse.mc-stan.org/t/horseshoe-prior-error-in-rstan/14565/1 "2020-04-23T20:03:06Z")

</div>

Can you please fix why my code produces an error??

```stan
data {
  int<lower=1> n; // Number of data
  int<lower=1> p; // Number of covariates
  matrix[n,p] X; // n-by-p design matrix
  real y[n]; // n-dimensional response vector
}

parameters {
  vector[p] beta;
  vector<lower=0>[p] lambda_sq;
  vector<lower=0>[p] omega;
  real<lower=0> tau_sq;
  real<lower=0> eta;
  real<lower=0> sigma;
}

transformed parameters {
  vector[n] theta ;
  theta = X * beta;
}

model {
  // Origianal horseshoe by carvalho + Parameter expansion on half-Cauchy
  //lambda ~ cauchy(0, 1) is equivalent with;
  omega ~ inv_gamma(1 / 2, 1);
  lambda_sq ~ inv_gamma(1 / 2, 1 ./ omega);
  //tau ~ cauchy(0, 1) is equivalent with;;
  eta ~ inv_gamma(1 / 2, 1);
  tau_sq ~ inv_gamma(1 / 2, 1 / eta);
  beta ~ normal(0, sigma * sqrt(tau_sq) * sqrt(lambda_sq) ); 
  y ~ normal(theta, sigma);
}

```

---

<div class="post-metadata">

**Author:** ![maxbiostat](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/maxbiostat/32/1326_2.png) [@maxbiostat](https://discourse.mc-stan.org/u/maxbiostat)\
**Post date:** [April 23, 2020, 8:42pm UTC](https://discourse.mc-stan.org/t/horseshoe-prior-error-in-rstan/14565/2 "2020-04-23T20:42:23Z")

</div>

It’s easier if you post what the error message is.

---

<div class="post-metadata">

**Author:** ![Se\_Yoon\_Lee](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/se_yoon_lee/32/7809_2.png) [@Se\_Yoon\_Lee](https://discourse.mc-stan.org/u/Se_Yoon_Lee)\
**Post date:** [April 23, 2020, 8:44pm UTC](https://discourse.mc-stan.org/t/horseshoe-prior-error-in-rstan/14565/3 "2020-04-23T20:44:33Z")

</div>

Do you know how to make 1/2 to be interpreted as 0.5?

It seems that error comes from “integer division implicitly rounds to integer. Found int division: 1 / 2”

---

<div class="post-metadata">

**Author:** ![maxbiostat](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/maxbiostat/32/1326_2.png) [@maxbiostat](https://discourse.mc-stan.org/u/maxbiostat)\
**Post date:** [April 23, 2020, 8:46pm UTC](https://discourse.mc-stan.org/t/horseshoe-prior-error-in-rstan/14565/4 "2020-04-23T20:46:37Z")

</div>

You can either do `0.5` or `1/2.0`, but these are warnings, not errors.

---

<div class="post-metadata">

**Author:** ![Se\_Yoon\_Lee](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/se_yoon_lee/32/7809_2.png) [@Se\_Yoon\_Lee](https://discourse.mc-stan.org/u/Se_Yoon_Lee)\
**Post date:** [April 23, 2020, 8:50pm UTC](https://discourse.mc-stan.org/t/horseshoe-prior-error-in-rstan/14565/5 "2020-04-23T20:50:14Z")

</div>

If I use `0.5` or `1/2.0`, then R aborted.

---

<div class="post-metadata">

**Author:** ![maxbiostat](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/maxbiostat/32/1326_2.png) [@maxbiostat](https://discourse.mc-stan.org/u/maxbiostat)\
**Post date:** [April 23, 2020, 8:58pm UTC](https://discourse.mc-stan.org/t/horseshoe-prior-error-in-rstan/14565/6 "2020-04-23T20:58:00Z")

</div>

Can you share your R code and maybe some test data? It helps also if you can post the result of `sessionInfo()`.

---

<div class="post-metadata">

**Author:** ![Se\_Yoon\_Lee](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/se_yoon_lee/32/7809_2.png) [@Se\_Yoon\_Lee](https://discourse.mc-stan.org/u/Se_Yoon_Lee)\
**Post date:** [April 24, 2020, 2:09am UTC](https://discourse.mc-stan.org/t/horseshoe-prior-error-in-rstan/14565/7 "2020-04-24T02:09:27Z")

</div>

[horseshoe\_pe.stan](https://discourse.mc-stan.org/uploads/short-url/39WbH5PiW5zL24udoy2xkM2ohQ2.stan) (773 Bytes)

---

<div class="post-metadata">

**Author:** ![Se\_Yoon\_Lee](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/se_yoon_lee/32/7809_2.png) [@Se\_Yoon\_Lee](https://discourse.mc-stan.org/u/Se_Yoon_Lee)\
**Post date:** [April 24, 2020, 2:10am UTC](https://discourse.mc-stan.org/t/horseshoe-prior-error-in-rstan/14565/8 "2020-04-24T02:10:33Z")

</div>

Please check this: [horseshoe\_pe.stan](https://discourse.mc-stan.org/uploads/short-url/39WbH5PiW5zL24udoy2xkM2ohQ2.stan) (773 Bytes)

You may use any (ordinary) linear regression for the y and X.
