0

I saw a Stan program where the data block contained int person[N_obs]. Is this creating an array of integers of size N_obs that is called with person?

socialscientist
  • 3,759
  • 5
  • 23
  • 58

1 Answers1

1

Yes, exactly. Brackets behind the variable names specify an array of the type that was specified before the name. In addition, for collection data types like vector and matrix, you need to specify the size behind the data type:

vector[N] y;
matrix[N, K] X;

You can also create arrays of collection data types. For example

vector[N] X[K];

would specify an array of K vectors of size N.

LukasNeugebauer
  • 1,331
  • 7
  • 10
  • The last code snippet's syntax is deprecated, I believe. Now it's `array[K] vector[N] X;` – socialscientist Sep 07 '22 at 01:34
  • I think that's a new alternative way instead of a complete replacement, but you're right. Yours is more modern, I got stuck at pystan 2.19. – LukasNeugebauer Sep 07 '22 at 16:47
  • It's deprecated (and for some reason, Stan tends to remove deprecated features instead of letting them break) and scheduled for removal in an upcoming update https://mc-stan.org/docs/reference-manual/brackets-array-syntax.html – socialscientist Sep 07 '22 at 21:12
  • Good to know thanks! Looks like I'll have to bring myself up to date soon ;) – LukasNeugebauer Sep 08 '22 at 13:11