Pars in sampling

Regarding the “pars” argument in the “sampling” function in rstan, the manual states “a vector of character strings specifying parameters of interest”. My question is as follows.

Suppose I have a model with two parameters (mu and theta). mu is a vector of length equal to a million and theta is a scalar. I am only interested in the posterior samples of theta. I believe specifying pars=c(“theta”) with include=TRUE will give me the posterior samples of theta only. However, what I am not sure about is that did Stan store the samples of mu while sampling but only returned the samples of theta (and hence, required a lot of memory while sampling since mu has a million parameters) or did it never store the samples of mu (and hence, did not require a lot of memory).

It stores mu temporarily so that it can calculate the posterior means of the million margins of mu but does not return the posterior draws of mu to R.

Thanks Ben. Suppose iter=1e3. Regarding storing mu temporarily, does it store all 1e3 samples of mu at once (i.e., 1e3 * 1e6 samples in total) or does it store only a subset?

Only after warmup

Is there a way to keep Stan from storing the transformed parameters during sampling?

I have a large model with a lot of transformed parameters, and it crashes when I try to run it. Do I have to move them to the model section to avoid this?

If you don’t want to store something, it is better to define it in the model block. But you can specify the names of those in pars and also include = FALSE to only store their averages.