Name Vector Elements


#1

Hi, is it possible in Stan to name the elements in the vector?
So instead of using indexing for accessing elements like v[1], I could use something like v[‘element1’] for instance?

Thanks,
Ryan


#2

No.


#3

No, like Bob said. However if the purpose is just for code clarity though then there are options, like v[element[1]] (if element if defined appropriately) that make it explicit to the reader that you are indexing v by “element”. But you can’t actually name the elements of v.


#4

And here the element variable would presumably have a different, informative name.


#5

We should implement enums.


#6

You mean in Stan? That probably wouldn’t be too hard.

Is there a realistic example where you’d like to do this? I’m having a hard time seeing the use case in the language.


#7

beta[income] where income is an enum that is defined as 2 or whatever.


#8

I understood what you were proposing. Just a lack of imagination on my part as to where it woul be useful.

For now, you can already name indexes as transformed data.

transformed data {
  int income = 1;
  int education = 2;
  int sex = 3;
parameters {
  vector[K] beta;
  ...
model {
  beta[income] ~ ...