Edit: because I think the way I reformulated this on github might be more clear?
Maybe I don’t understand how mi()
works? I’m learning about measurement error models.
If x
has missing data and w
is a proxy, I can do bf(y ~ mi(x)) + bf(x | mi() ~ w)
.
I’m trying to understand how comparable this model is to y ~ MeasError(x,w)
using the R package mecore.
MeasErr(y,w) ~ x
is a valid model. Can brms
fit a comparable one?
Original Post Below
I am working on a modeling problem with missing data on the outcomes. My goal is to fit a bivariate regression.
# simulate data
N <- 100
x <- rnorm(N, 0, 1)
y <- x + rnorm(N, 0, 0.5) + 1
w <- y + rnorm(N, 0, 0.5)
df <- data.table(x,y,w)
if(m < N){
df <- df[sample(nrow(df), 20), y.obs := y]
} else {
df <- df[, y.obs := y]
}
If missing data is on the RHS, the following model works great:
model <- brm(formula=bf(x ~ mi(y.obs)) + bf(y.obs | mi() ~ w) + set_rescor(FALSE),data=df)
But if the missing data is on the LHS, I get an error in fitting the model: invalid type (list) for variable 'mi(y.obs)'
model <- brm(formula=bf(y.obs | mi() ~ w) + bf(mi(y.obs) ~ x) + set_rescor(FALSE), data=df)
bf(y.obs | mi() ~ w) + bf(mi(y.obs) ~ w) + set_rescor(FALSE)
outputs
y.obs | mi() ~ w
mi(y.obs) ~ x
Which looks right to me, but I don’t understand why brms is having trouble.
- Operating System: Rocky Linux release 8.4 (Green Obsidian)
- brms Version:2.16.3
Thank you!