# Hurdle Prior or Piecewise Function?

**URL:** <https://discourse.mc-stan.org/t/hurdle-prior-or-piecewise-function/36462>\
**Category:** Modeling\
**Tags:** specification, brms\
**Created:** [September 3, 2024, 12:34am UTC](https://discourse.mc-stan.org/t/hurdle-prior-or-piecewise-function/36462 "2024-09-03T00:34:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jweverka](https://avatars.discourse-cdn.com/v4/letter/j/f04885/32.png) [@jweverka](https://discourse.mc-stan.org/u/jweverka)\
**Post date:** [September 3, 2024, 12:34am UTC](https://discourse.mc-stan.org/t/hurdle-prior-or-piecewise-function/36462/1 "2024-09-03T00:34:38Z")

</div>

Hello,

I’m trying to use brms to fit a nonlinear model of the form

y \sim Lognormal(\mu , \sigma) \\ \mu = a - (b\_1x)/(1 + b\_2x^2)

The part of the model that I’m unsure how to specify is the idea that the parameter b\_1 depends on x, such that when x is below a certain threshold value, b\_1 = 0, (and thus \mu = a), and above the threshold b\_1 is some positive value. Additionally, there is some grouping in my data, so both the threshold location and the value of b\_1 above the threshold vary among groups (as a random effect).

It seems to me that the distribution of b\_1 across all groups should follow something like a hurdle-lognormal distribution. Is there a way to specify this as a prior for a parameter or a random effect?

Alternatively, maybe it could be a piecewise function where below the threshold x = t\_{[i]} the it’s just \mu = a and above it’s the full function. Can anyone provide insight on the best way to specify this model, and how it can be coded in brms?

---

<div class="post-metadata">

**Author:** ![Corey.Plate](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/corey.plate/32/20600_2.png) [@Corey.Plate](https://discourse.mc-stan.org/u/Corey.Plate)\
**Post date:** [September 8, 2024, 4:44am UTC](https://discourse.mc-stan.org/t/hurdle-prior-or-piecewise-function/36462/2 "2024-09-08T04:44:46Z")

</div>

If b1 is always zero below a certain threshold, then I would think a piecewise function is the way to go:

```stan
if (x < t) {
 mu = a;
} else {
 mu = a - (b1 * x) / (1 + b2 * x^2);
}

```

If it has some probability of being zero or not below a certain threshold, then I think you need a hurdle model.

However, as you probably noted from my use of Stan’s native code, I do not have any knowledge of how to specify a piecewise model in brms.
