Predictor including error but allowing to be estimate by a supplementary dataset

Hi everybody,

I am looking for a solution of taking account of uncertainty (or measuring error) which can be estimated by supplementary data. I have trying to learn the mi(…) function, the me(…) function and bf(…, nl = TRUE), but so far I find no working/correct codes.

Please consider the following data. My major propose is to fit d1$y against a predictor among N subjects by using a linear model, but I cannot directly find the value of the predictor without uncertainty/measuring error. Therefore, I collected another dataset d2, which records the repeated measurements of x for each subject in d1.

d1 <-
    subject = LETTERS[1:20],
    y = (1:20) + rnorm(10, 0, 0.1)
d2 <-
    subject = LETTERS[1:20] |> rep(each = 50),
    x = ((1:20)/2) %>% rep(each = 50) + rnorm(1000, 0, 0.2)
# join d2 into d1
d <- merge(d1, d2, by = "subject")

My ultimate propose is to fitting d1$y against x, and simultaneously the uncertainty of d1$x can be taking account based on d2$x. Is it possible to do it by BRMS? If it is possible, please teach me how to write a proper brmsformula to deal with it.

Many thanks to any response,
All best.

Welcome to the Stan Forum!

you can implement measurement error models with brms, look for me here (there is an entire paragraph about measurement error models):

(it looks as if the me will be depreciated because it’s functionality is also available through mi, but me might be easier to use.)

cheers - Guido


You can see some more examples here. You’ll need to join the two data sets together because brms will want a single dataframe.


Many thanks. Reading it now!