- Operating System: MacOS
- brms Version: 2.18.0
I have a problem where I’ve collected data at 2 conditions. For one condition, the data are truncated. They’re not truncated for the second condition. Ignoring truncation for a moment, my substantive model is:
where x_i is an 0/1 dummy variable for condition. To handle the truncation, I’d like to a fit a truncated normal version of the model where there is truncation for when x = 0, but no truncation otherwise. Here are some simulated data of that form, and my attempt to fit the model with brm()
.
# load
library(tidyverse)
library(brms)
# simulate
set.seed(1)
dat <- tibble(y = rnorm(n = 1000)) %>%
# truncate
filter(y > -2) %>%
# subset to just 100 cases from the truncated distribution
slice_sample(n = 100) %>%
# add in non-truncated cases
bind_rows(tibble(y = rnorm(n = 100))) %>%
# add a truncation index
mutate(lb = rep(c(-2, -Inf), each = 100),
# add a predictor variable, which is confounded with the truncation periods
x = rep(0:1, each = 100))
# fit the model with weakly regularizing priors
fit <- brm(
data = dat,
family = gaussian,
y | trunc(lb = lb) ~ 0 + Intercept + x,
prior = prior(normal(0, 1), class = b, coef = Intercept) +
prior(normal(0, 1), class = b, coef = x) +
prior(exponential(1), class = sigma),
seed = 1, chains = 1,
# intentionally set small for debugging
iter = 10
)
I’ve tried tricks lke setting init_r = 0.2
or init = 0
. I’ve even manually set my init
values, like init = list(list(b = c(0, 0), sigma = 1))
. No matter what, I always end up with warnings like this:
Chain 1: Rejecting initial value:
Chain 1: Gradient evaluated at the initial value is not finite.
Chain 1: Stan can't start sampling from this initial value.
However, if I give up on the conditional truncation idea and manually set something like
y | trunc(lb = -Inf) ~ 0 + Intercept + x
or
y | trunc(lb = -5) ~ 0 + Intercept + x
the model fits just fine. What am I missing?