I am working on a model in which I would like the coefficient of one variable to be modeled as explicitly dependent on other variables. Generally speaking, the scenario is one in which we have a dichotomous outcome Y, a three-level predictor of interest A (0, 1, 2), and multiple additional covariates (x1, x2, x3). I would like to estimate the overall effect of A on Y, but also allow this effect to vary with respect to the covariates. I run into an error when running the model included below (“Error: Factors with more than two levels are not allowed as covariates.”). Any thoughts on how to best proceed (or approach this problem in a different way)?
df <- tibble( a = rep(c(0, 1, 2), each = 50), x1 = rnorm(150), x2 = rnorm(150), x3 = rnorm(150), y = rbinom(150, size = 1, prob = 0.5) ) %>% mutate( a = factor(a) ) model <- brm( data = df, family = bernoulli, formula = bf(y ~ (b1 * a) + b2 + b3 + b4, b1 ~ 1 + x1 + x2 + x3, b2 ~ 0 + x1, b3 ~ 0 + x2, b4 ~ 0 + x3, nl = TRUE), prior = c(prior(normal(0, 1.5), nlpar = "b1"), prior(normal(0, 1.5), nlpar = "b2"), prior(normal(0, 1.5), nlpar = "b3"), prior(normal(0, 1.5), nlpar = "b4")), iter = 1000, warmup = 200, chains = 1, cores = 1, seed = 19 )
- Operating System: macOS Mojave 10.4.3
- brms Version: 2.8.0