I am using imputation during model fitting. The outcome variable treat
is binary while the predictor variable c1
which has missing values that I want to impute is continuous.
What I want here is to fit the outcome model using family bernoulli
and to do the imputation of the predictor c1
using another family, for example gaussian
.
When I run the model, I get the error:
Error: Argument ‘mi’ is not supported for family ‘bernoulli(logit)’.
##my model
bform <- bf(treat | mi()~ mi(c1)+(1|group)) +
bf(c1| mi() ~ c2) + set_rescor(FALSE)
m <-brm(bform, data=dt, family = bernoulli())
##sample data
dt = read.table(header = TRUE, text = "
n r r/n group treat c2 c1 weights
62 3 0.048387097 1 0 0.1438 1.941115288 1.941115288
96 1 0.010416667 1 0 0.237 1.186583128 1.186583128
17 0 0 0 0 0.2774 1.159882668 3.159882668
41 2 0.048780488 1 0 0.2774 1.159882668 3.159882668
212 170 0.801886792 0 0 0.2093 1.133397521 1.133397521
143 21 0.146853147 1 1 0.1206 1.128993008 1.128993008
143 0 0 1 1 0.1707 1.128993008 2.128993008
143 33 0.230769231 0 1 0.0699 1.128993008 1.128993008
73 62 1.260273973 0 1 0.1351 NA 1.121927228
73 17 0.232876712 0 1 0.1206 NA 1.121927228")
Thanks in advance for any help.
1 Like
See vignette("brms_multivariate")
for how to specify different families for different models parts.
1 Like
Thanks, @paul.buerkner. vignette("brms_multivariate")
is straightforward.
I would like to know whether (1) below is doing what I want to accomplish with (2). If not, how could the problem of (2) be solved?
(1) When I fit the multivariate model without adding | mi()
on the left-hand side of bf_outcome
, the model runs well:
bf_outcome <- bf(treat ~ mi(c1)+(1|group)) + bernoulli()
bf_imputation <-bf(c1| mi() ~ c2) + gaussian()
imputed_fit <-brm(bf_outcome + bf_imputation + set_rescor(FALSE),
data=dt, chains = 2, cores = 2,
control = list(adapt_delta = 0.95)
)
(2) But when I add | mi()
on the left-hand side of bf_outcome
to ensure that missings in both variables will be modeled rather than excluded
, I get the error message:
bf_outcome <- bf(treat | mi()~ mi(c1)+(1|group)) + bernoulli()
bf_imputation <-bf(c1| mi() ~ c2) + gaussian()
imputed_fit <-brm(bf_outcome + bf_imputation + set_rescor(FALSE),
data=dt, chains = 2, cores = 2,
control = list(adapt_delta = 0.95)
)
Error: Argument ‘mi’ is not supported for family ‘bernoulli(logit)’.
Thanks in advance for any help.
1 Like
Did you ever find a solution to this problem? I’m having the same issue.
This is not possible currently because stan does not (directly) support discrete parameters. One could work around it via marginalisation but this is currently too much work just for that specific use case that I cant put in brms at the moment.
2 Likes