# Horseshoe prior error in rstan

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

``````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);
}
``````

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

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”

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

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

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

horseshoe_pe.stan (773 Bytes)

Please check this: horseshoe_pe.stan (773 Bytes)

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