Pivoting posteriors
In
Stan, when a parameter is declared as an array, the samples/draws data frame will have columns that use the [i]
notation to denote the i
-th element of the array. For example, suppose we had a model with two parameters – \(\lambda_1\)
and a \(\lambda_2\)
. Instead of declaring them individually – e.g. lambda1
and lambda2
, respectively – we may declare them as a single lambda
array of size 2:
parameters {
real lambda[2];
}
When we sample from that model, we will end up with samples for lambda[1]
and lambda[2]
. We want to extract the i
from [i]
and the name of the parameter into separate columns, yielding a tidy dataset.