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