# Bounded parameters and effect

**URL:** <https://discourse.mc-stan.org/t/bounded-parameters-and-effect/8363>\
**Category:** brms\
**Created:** [April 4, 2019, 10:10am UTC](https://discourse.mc-stan.org/t/bounded-parameters-and-effect/8363 "2019-04-04T10:10:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![blackrabite](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/blackrabite/32/8887_2.png) [@blackrabite](https://discourse.mc-stan.org/u/blackrabite)\
**Post date:** [April 4, 2019, 10:10am UTC](https://discourse.mc-stan.org/t/bounded-parameters-and-effect/8363/1 "2019-04-04T10:10:47Z")

</div>

I have very simple non-linear model:

```
x <- rnorm(100)
n <- rbinom(100, 1, 0.5)
y <- 1.5-1*n + exp(x) + rnorm(100, 0, 0.1)

```

Where “n” is simply a 0 or 1 grouping variable, like male/female etc…

> fit ← brm(bf(y ~ a + b \* exp(x), nl=TRUE, a ~ 1 + n, b ~ 1), data=data.frame(y, x, n),prior= prior(normal(0,1), nlpar=“a”, lb=0) +prior(normal(0,1), nlpar=“b”), cores=4 )

Bounding parameter “a” to be positive (it has to be in my model), force the effect of “n” to always be positive, is there a workaround for this without splitting “a” into 2 parameters?

---

<div class="post-metadata">

**Author:** ![increasechief](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/increasechief/32/2039_2.png) [@increasechief](https://discourse.mc-stan.org/u/increasechief)\
**Post date:** [April 5, 2019, 3:00am UTC](https://discourse.mc-stan.org/t/bounded-parameters-and-effect/8363/2 "2019-04-05T03:00:39Z")

</div>

Where did you learn about this particular model?

---

<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:** [April 5, 2019, 3:04pm UTC](https://discourse.mc-stan.org/t/bounded-parameters-and-effect/8363/3 "2019-04-05T15:04:22Z")

</div>

The easiest and the most general solution would be to model a on the log scale so that exp(a) is alway positive. I.e. `y ~ exp(a) + b * exp(x)`

---

<div class="post-metadata">

**Author:** ![increasechief](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/increasechief/32/2039_2.png) [@increasechief](https://discourse.mc-stan.org/u/increasechief)\
**Post date:** [April 5, 2019, 3:36pm UTC](https://discourse.mc-stan.org/t/bounded-parameters-and-effect/8363/4 "2019-04-05T15:36:39Z")

</div>

How does splitting `a` to address the sign of the parameter work? Like a piecewise function?

---

<div class="post-metadata">

**Author:** ![blackrabite](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/blackrabite/32/8887_2.png) [@blackrabite](https://discourse.mc-stan.org/u/blackrabite)\
**Post date:** [April 5, 2019, 6:48pm UTC](https://discourse.mc-stan.org/t/bounded-parameters-and-effect/8363/5 "2019-04-05T18:48:56Z")

</div>

I mean something like this:  
`

> fit ← brm(bf(y ~ (aI+aN) + b \* exp(x), nl=TRUE, aI + b ~ 1, aN ~ 0 + n), data=data.frame(y, x, n),prior= prior(normal(0,1), nlpar=“aI”, lb=0) + prior(normal(0,1), nlpar=“aN”) +prior(normal(0,1), nlpar=“b”), cores=4 )

`
