Array of ordered vectors?

I want to specify an N array of ordered 2 vectors. Something like

// doesn't work
vector[N] ordered[2] mu;
vector[N] ordered mu[2];

what is the best way to achieve this?

Playing around a bit, I was able to achieve what I wanted. Though I think it would be nice if we could specify an array of ordered vectors instead of what I did.

The problem I’m working on involved a mixture of two distributions where the intercept was allowed to vary within each mixture (ala hierarchical). However, I wanted one of the mixture intercepts to be always less than the other. I enforced this by creating two vectors where one is strictly negative and the other one is strictly positive.

Forgive the nested loop, I was doing some stuff above it and know that I could re-write this example a bit more efficiently.

parameters {
  vector<lower=-3, upper=0>[N] mu1;
  vector<lower=0, upper=3>[N] mu2;
transformed parameters {
  matrix[2, N] mu_ind;
  for (i in 1:2){
    //doin' some other stuff here also
     for (n in 1:N) {
         mu_ind[i, n] = i == 1 ? mu1[n] : mu2[n];

Have you tried

ordered[2] mu[N];


1 Like

This is hilarious, I tried that but got an error so abandoned it. Trying again, all I had to modify was to specify two priors (not one) as

  mu[, 1] ~ normal(-0.5, 1.0);
  mu[, 2] ~ normal(0.5, 1.0);