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.
library(data.table)
library(magrittr)
library(brms)
set.seed(1223456789)
d1 <-
data.table(
subject = LETTERS[1:20],
y = (1:20) + rnorm(10, 0, 0.1)
)
d2 <-
data.table(
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.