Name Vector Elements

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

No.

1 Like

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.

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

We should implement enums.

1 Like

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.

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

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] ~ ...