# Lb in brms prior

**URL:** <https://discourse.mc-stan.org/t/lb-in-brms-prior/5880>\
**Category:** brms\
**Created:** [October 4, 2018, 6:03pm UTC](https://discourse.mc-stan.org/t/lb-in-brms-prior/5880 "2018-10-04T18:03:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vasishth](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/vasishth/32/142_2.png) [@vasishth](https://discourse.mc-stan.org/u/vasishth)\
**Post date:** [October 4, 2018, 6:03pm UTC](https://discourse.mc-stan.org/t/lb-in-brms-prior/5880/1 "2018-10-04T18:03:17Z")

</div>

I want to fit a model where the prior for the parameter mu is bounded from below by 0. This can be done like this in rstan:

```stan
"data {
  int N;
  real y[N]; // data
}
parameters {
real<lower=0> mu;
real<lower=0> sigma;
}
model {
  // priors
	mu ~ normal(0,2000);
	sigma ~ normal(0,500);
  // likelihood
  y ~ normal(mu,sigma);
}
generated quantities {
  vector[N] y_sim;
 // posterior predictive
  for(i in 1:N) {
    y_sim[i] = normal_rng(mu,sigma);
  }
}

```

I generated fake data to fit this model in brms:

```
set.seed(123)
N <- 500
true_mu <- 400
true_sigma <- 125
y <- rnorm(N, true_mu, true_sigma)

y <- round(y) 
fake_data <- data.frame(y=y)

```

Then I tried to bound the intercept from below in brms:

```
priors <- c(set_prior("normal(0, 2000)", 
                      class = "Intercept",lb=0),
            set_prior("normal(0, 500)", 
                      class = "sigma"))

```

I get the error:

Error: Currently boundaries are only allowed for population-level and autocorrelation parameters.

The intercept is surely a population level parameter? Is this a bug?

---

<div class="post-metadata">

**Author:** ![paul.buerkner](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/paul.buerkner/32/3303_2.png) [@paul.buerkner](https://discourse.mc-stan.org/u/paul.buerkner)\
**Post date:** [October 4, 2018, 6:52pm UTC](https://discourse.mc-stan.org/t/lb-in-brms-prior/5880/2 "2018-10-04T18:52:51Z")

</div>

It is not a bug. As explained in `?set_prior` and `?brmsformula`, the intercept is handled separately for reasons of efficiency. If you want the intercept to be included in the rest of the population-level effects, go for `y ~ 0 + Intercept + ...` and then change the prior accordingly to `class = "b"`.

---

<div class="post-metadata">

**Author:** ![vasishth](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/vasishth/32/142_2.png) [@vasishth](https://discourse.mc-stan.org/u/vasishth)\
**Post date:** [October 4, 2018, 8:20pm UTC](https://discourse.mc-stan.org/t/lb-in-brms-prior/5880/3 "2018-10-04T20:20:32Z")

</div>

oops. sorry for the dumb question!

---

<div class="post-metadata">

**Author:** ![jverissimo](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jverissimo/32/3260_2.png) [@jverissimo](https://discourse.mc-stan.org/u/jverissimo)\
**Post date:** [October 6, 2018, 9:50am UTC](https://discourse.mc-stan.org/t/lb-in-brms-prior/5880/4 "2018-10-06T09:50:46Z")

</div>

Follow-up: Both `y ~ 0 + Intercept + ...` and `y ~ 0 + intercept + ...` seem to work (capital and small letter), but `?set_prior` mentions the small letter one. Are they the same internal variable?

---

<div class="post-metadata">

**Author:** ![paul.buerkner](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/paul.buerkner/32/3303_2.png) [@paul.buerkner](https://discourse.mc-stan.org/u/paul.buerkner)\
**Post date:** [October 6, 2018, 3:38pm UTC](https://discourse.mc-stan.org/t/lb-in-brms-prior/5880/5 "2018-10-06T15:38:55Z")

</div>

Both do the same, but I would recommend using `Intercept` because it is the same name as if you were modeling an intercept in the usual way. I will change the documentation accordingly. Perhaps I even deprecate `intercept` at some point.
