Truncation of outcome variable in map2stan


I’m having some issues with truncation in map2stan. I’m aiming to truncate the outcome variable of a multilevel model specified using map2stan. Here’s some dummy code:

nullModel <- map2stan(
      outcome ~ dnorm(mu, sigma) & T[0,5],
      mu <- a + beta * predictor,

      # Individual-level priors
      a[ID] ~ dnorm(a_mu, a_sig),
      beta[ID] ~ dnorm(beta_mu, beta_sig),
      sigma ~ dcauchy(0, 2),

      # Hyperparameter priors
      a_mu ~ dnorm(0, 2),
      a_sig ~ dcauchy(0, 1),
      beta_mu ~ dnorm(0, 2),
      beta_sig ~ dcauchy(0, 1)

), data = d )

However, this returns the following error message:
Outcomes in truncated distributions must be univariate.
Found outcome expression: outcome with non-univariate type: real[ ]

Is this an issue with the model/data specification? As I’m using map2stan to interface with stan, I’m not specifying the variable types directly.

Any help is much appreciated!

1 Like

Sorry for not getting to you earlier. I have never used map2stan myself, but this might be a bug (I know that this is a limitation at the Stan level). You should however be able to easily write the same model in brms (which is also a bit easier to get help with here on the forums, as there is a LOT of brms users out there).

Best of luck!