Vector and matrix variables with dimension of size 0


#1

the Stan language allows vector and matrix declarations:

  matrix[0,0] m0;
  vector[0] v0;
  row_vector[0] rv0;

would objects like the above ever be used?


#2

#3

Yes. Typically not declared with the literal 0, but usually with variables.
It’s a quick way to sample from the prior. Or have 0-length observations
for a group.


#4

Yeah we do what Daniel mentioned a lot in the Stan programs for rstanarm. For example, it allows us to do something like

data {
  ...
  int<lower=0,upper=1> has_intercept;
}
parameters {
  ...
  real alpha[has_intercept];
}

so alpha will only have positive length if the user has specified a model with an intercept.

I guess I used an array and not a vector in that example, but it’s the same idea.