How can we extract samples in correct sequence and simultaneously group array together

Operating System: Windows 10

Interface Version: rstan 2.18.1

Compiler/Toolkit: Not sure

The “extract” function in “rstan” package permute the iterations if permuted=T(default).

I wanna the samples with the correct iteration sequence, so I used permuted=F, but now it is inconvenient to obtain the samples of array. For example, if a 5*5 matrix called w is included in the parameter block, then permuted=F shows each element w[i, j] in a different column.

How can I satisfy both conditions?

(1) Correct iteration sequence as in permuted=F.

(2) Group the elements of arrays together as in permuted=T. For example

MH=extract(s, permuted=T)

returns a list MH, where MH$w is a matrix, rather than separately shows each element of w.

Thank you.

1 Like

You would have to do extract with permuted = FALSE and then change the dimensions of the resulting array to be the ones you want, remembering that everything is in column-major order.

Got it.
Thanks, Ben.