Brms: multivariate regression with response variables of different length

If I do

library(brms)
test_data <- data.frame(a = rbinom(500, 1, .5), 
                        b = rbinom(500, 1, .5), 
                        c = sample(c(1:20), 500, TRUE))
model_formula <- brmsformula(mvbind(a, b) ~ (1|g1|c))
make_stancode(model_formula, data = test_data, 
              family = bernoulli(link = "logit"), backend = "cmdstanr")

Then I get stan code that includes

  int<lower=1> N;  // total number of observations
  int<lower=1> N_a;  // number of observations
  int Y_a[N_a];  // response variable
  int<lower=1> N_b;  // number of observations
  int Y_b[N_b];  // response variable

with the possibility of different numbers of observations for Y_a and Y_b.

However, I cannot figure out how to actually create/fit a multivariate model with response vectors of different lengths. If I do, for example:

test_data <- data.frame(a = rbinom(500, 1, .5), 
                        b = c(rbinom(400, 1, .5), rep(NA, 100)), 
                        c = sample(c(1:20), 500, TRUE))
model_formula <- brmsformula(mvbind(a, b) ~ (1|g1|c))
data <- make_standata(model_formula, data = test_data, 
                      family = bernoulli(link = "logit"))

then make_standata() drops the rows with NAs for either response variable from both of the response variables. How do I pass response vectors of different lengths?

check out ?resp_subset

2 Likes