# Custom prior nonlinear model

**URL:** <https://discourse.mc-stan.org/t/custom-prior-nonlinear-model/13393>\
**Category:** brms\
**Created:** [February 28, 2020, 10:58pm UTC](https://discourse.mc-stan.org/t/custom-prior-nonlinear-model/13393 "2020-02-28T22:58:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nelsjohnson](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/nelsjohnson/32/4746_2.png) [@nelsjohnson](https://discourse.mc-stan.org/u/nelsjohnson)\
**Post date:** [February 28, 2020, 10:58pm UTC](https://discourse.mc-stan.org/t/custom-prior-nonlinear-model/13393/1 "2020-02-28T22:58:41Z")

</div>

Please also provide the following information in addition to your question:

- Operating System: win10
- brms Version: 2.11.1

I have Bernoulli data where the probability p = exp(-lambda). I am implementing it as a generalized nonlinear model. I want to place a beta(p;0.5,0.5) prior on p, which is equivalent to placing a beta(p=exp(-lambda);0.5,0.5)\*exp(-lambda) prior on lambda. As such, I am trying to use the prior\_string function to create the custom prior. This is my first time trying this out. Right now I use the following prior string code:

`brm_priors <- prior_string("target += beta_lpdf(exp(-b_theta) | 0.5, 0.5) - b_theta", check = F)`

When I do this I get the following error:

> Error: Priors on population-level coefficients are required in non-linear models, but none were found for parameter ‘theta’. See help(set\_prior) for more details.

So I turned checking on:

`brm_priors <- prior_string("target += beta_lpdf(exp(-b_theta) | 0.5, 0.5) - b_theta", check = T)`

and got the following error:

> Error: The following priors do not correspond to any model parameter:  
> b ~ target += beta\_lpdf(exp(-b\_theta) | 0.5, 0.5) - b\_theta  
> Function ‘get\_prior’ might be helpful to you.

Previously I had placed an exponential(1) prior on b\_theta, so I feel confident I am using the correct parameter. Previously, my stancode looked like:

`target += exponential_lpdf(b_theta | 1) - 59 * exponential_lccdf(0 | 1);`

Any advice on how to use the custom prior and the a generalized nonlinear model without generating a warning or error?

Here’s the brms code:

```no-highlight
brm.out <- brm(bf(y ~ exp(-theta), theta ~ 1, nl = T),
               prior = brm_priors,
               family = bernoulli("identity"),
               chains = 2, cores = 2,
               iter = 2000, warmup = 1000, thin = 1, 
               data = dat)

```

Edit: fixed formatting and added brm model code.  
Edit2: fixed a copy paste error. That’s what I get for making this post the last thing I do before leaving work on a Friday.

---

<div class="post-metadata">

**Author:** ![Ara\_Winter](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/ara_winter/32/4284_2.png) [@Ara\_Winter](https://discourse.mc-stan.org/u/Ara_Winter)\
**Post date:** [March 1, 2020, 2:20pm UTC](https://discourse.mc-stan.org/t/custom-prior-nonlinear-model/13393/2 "2020-03-01T14:20:19Z")

</div>

Hi there! Can you provide the R code and use the ``` to set the code off. This will make it easier to answer your question. If you could include the full brms model that would be great.

---

<div class="post-metadata">

**Author:** ![nelsjohnson](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/nelsjohnson/32/4746_2.png) [@nelsjohnson](https://discourse.mc-stan.org/u/nelsjohnson)\
**Post date:** [March 2, 2020, 5:48pm UTC](https://discourse.mc-stan.org/t/custom-prior-nonlinear-model/13393/3 "2020-03-02T17:48:01Z")

</div>

I made the edits you suggested.

---

<div class="post-metadata">

**Author:** ![Ara\_Winter](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/ara_winter/32/4284_2.png) [@Ara\_Winter](https://discourse.mc-stan.org/u/Ara_Winter)\
**Post date:** [March 3, 2020, 2:25am UTC](https://discourse.mc-stan.org/t/custom-prior-nonlinear-model/13393/4 "2020-03-03T02:25:58Z")

</div>

Can you run the get\_prior on the model as well? Usually that error means a mismatch between your model and what is in your custom prior.
