Lognormal vs shifted_lognormal vs GEV measurement error models in brms

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:

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:

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.

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

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

1 Like

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.

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

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?

1 Like

Thank you, that works.