Why does fitting with trunc() seem to take much longer?

A model without trunc() finishes okay, but when I add trunc() it seems to hang forever.

n <- 10000
df <- n - 2

stanvars <- stanvar(df,name='df')
priors = c(prior(inv_gamma(0.001,0.001), class = sigma),
           prior(student_t(df, 0, 3), class = b))
myfit <- 
  brm(data = d, family = student,
      someresp | trunc(lb = 0, ub = 24) ~ 0 + Intercept + somepred,
      prior = priors,
      iter = 2000, warmup = 1000, chains = 4, cores = 4,
      seed = 4, stanvars = stanvars)
pp_check(myfit)

Hi,
truncated distributions are somewhat expensive to compute and (probably more importantly) can introduce a lot of weirdness in your posterior if the truncation does not really fit the data well, which can then lead the sampler to need more steps per iteration. Additionally, sometimes if the truncation is in the very tails (i.e. when the truncation bound is roughly > 10*sigma away from the predicted mean), there can be some numerical instabilities. Hard to say what is the problem without having access to the data you are using (is this real dataset? simulated?). Are all your observed data within the truncated region? Is there a lot of observations close to the boundary? Do you see some warnings if you run just a single chain?

Best of luck with your model!

4 Likes