# Lognormal vs shifted\_lognormal vs GEV measurement error models in brms

**URL:** https://discourse.mc-stan.org/t/lognormal-vs-shifted-lognormal-vs-gev-measurement-error-models-in-brms/28657
**Category:** brms
**Tags:** stan
**Created:** [August 26, 2022, 12:52am UTC](https://discourse.mc-stan.org/t/lognormal-vs-shifted-lognormal-vs-gev-measurement-error-models-in-brms/28657 "2022-08-26T00:52:34Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![stu.donovan](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/stu.donovan/32/8421_2.png) [@stu.donovan](https://discourse.mc-stan.org/u/stu.donovan)
#### Post date: [August 26, 2022, 12:52am UTC](https://discourse.mc-stan.org/t/lognormal-vs-shifted-lognormal-vs-gev-measurement-error-models-in-brms/28657/1 "2022-08-26T00:52:34Z")

</div>

I’m estimating a model that consists of four equations: One binomial equation in y that has three explanatory variables, x1, x2, and x3, which are measured with error. As the three explanatory variables are bounded to be positive, I specify the measurement error (ME) equations to be lognormal as below:

> form.mod ← bf(y | trials(y\_tot) ~ mi(x1) + mi(x2) + mi(x3)) + binomial()  
> form.me1 ← bf(x1 | mi(x1\_sd) ~ 1) + lognormal()  
> form.me2 ← bf(x2 | mi(x2\_sd) ~ 1) + lognormal()  
> form.me3 ← bf(x3 | mi(x3\_sd) ~ 1) + lognormal()

This model runs fine.

As a sensitivity check, however, I figured I’d try some alternative distributions for the ME equations, like the shifted\_lognormal:

> form.mod ← bf(y | trials(y\_tot) ~ mi(x1) + mi(x2) + mi(x3)) + binomial()  
> form.me1 ← bf(x1 | mi(x1\_sd) ~ 1) + shifted\_lognormal()  
> form.me2 ← bf(x2 | mi(x2\_sd) ~ 1) + shifted\_lognormal()  
> form.me3 ← bf(x3 | mi(x3\_sd) ~ 1) + shifted\_lognormal()

This model returns the following error when compiling the Stan program:

```no-highlight
Compiling Stan program...
Error in stanc(file = file, model_code = model_code, model_name = model_name, : 0

Syntax error in 'string', line 41, column 21 to column 31, parsing error:

Expression expected. Ill-formed expression. Suggested alternatives: a standalone identifier, a function application, an identifier followed by an operator or an identifier followed by an index.

```

Finally, I thought I’d try the generalised extreme value distribution for the ME equations:

> form.mod ← bf(y | trials(y\_tot) ~ mi(x1) + mi(x2) + mi(x3)) + binomial()  
> form.me1 ← bf(x1 | mi(x1\_sd) ~ 1) + gen\_extreme\_value()  
> form.me2 ← bf(x2 | mi(x2\_sd) ~ 1) + gen\_extreme\_value()  
> form.me3 ← bf(x3 | mi(x3\_sd) ~ 1) + gen\_extreme\_value()

Which returns the following error during compilation:

```no-highlight
Compiling Stan program...
Error in stanc(file = file, model_code = model_code, model_name = model_name, : 0

Semantic error in 'string', line 160, column 9 to column 11:

Identifier 'xi' is already in use.

```

Has anyone encountered this behaviour in brms before and/or know what I might be doing wrong? I can upload a sample of the data and more code to create a reprex if that would be helpful.

---

<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: [August 26, 2022, 7:31am UTC](https://discourse.mc-stan.org/t/lognormal-vs-shifted-lognormal-vs-gev-measurement-error-models-in-brms/28657/2 "2022-08-26T07:31:30Z")

</div>

could be a bug. does this still occur in brms 2.17+?

if yes, do you habe a  
minimal reproducible example for me?

---

<div class="post-metadata">

### Author: ![stu.donovan](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/stu.donovan/32/8421_2.png) [@stu.donovan](https://discourse.mc-stan.org/u/stu.donovan)
#### Post date: [August 26, 2022, 11:06am UTC](https://discourse.mc-stan.org/t/lognormal-vs-shifted-lognormal-vs-gev-measurement-error-models-in-brms/28657/3 "2022-08-26T11:06:55Z")

</div>

Hi @paul.buerkner, I’m running brms version 2.17.0.

Further testing suggests the model runs fine when the three measurement error equations are specified as `lognormal`, `weibull`, or `frechet` families but not `shifted_lognormal` or `gen_extreme_value` families.

I’ll work on a more complete reprex tomorrow (it’s late in Australia!) but in case you have time today, [here’s a link to the brms model for the lognormal specification](https://1drv.ms/u/s!ApES-77Jl8sUjf4QTgojxYyGD2silA?e=esVzRn).

P.s. As always, thanks for your efforts in sustaining / developing the amazing package that is brms …

---

<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: [August 26, 2022, 2:20pm UTC](https://discourse.mc-stan.org/t/lognormal-vs-shifted-lognormal-vs-gev-measurement-error-models-in-brms/28657/4 "2022-08-26T14:20:00Z")

</div>

I think I have found both issues and fixed them already on github. Can you try it out and see if it works for you too?

---

<div class="post-metadata">

### Author: ![stu.donovan](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/stu.donovan/32/8421_2.png) [@stu.donovan](https://discourse.mc-stan.org/u/stu.donovan)
#### Post date: [September 19, 2022, 1:37am UTC](https://discourse.mc-stan.org/t/lognormal-vs-shifted-lognormal-vs-gev-measurement-error-models-in-brms/28657/5 "2022-09-19T01:37:07Z")

</div>

Thank you, that works.
