I’m using the rstan package and noticed that it outputs rhat even if I run only one chain. To my understanding, calculating R-hat requires at least two chains. I wonder how r hat is being calculated in rstan under this condition.

I’m pretty sure that Stan uses split-R-hat, so if there are m chains, you’ll get 2m pieces which can be used for R-hat. I will always run multiple chains, but if you have just 1 chain, it is still split in two.

Thanks for the information! If I run 1 chain with 2000 iterations, does that mean the 2000 iterations will be split into two sets of 1000 iterations each, or will I get 2000 samples in total?

If you run 1 chain with 1000 warmup and 1000 saved iterations, then the 1000 saved iterations will be saved into two sets when computing split R-hat. But they are put back together when the simulations are sent out of Stan. In general, if you run m chains for n saved iterations each, Stan will compute split R-hat by splitting them into 2m chains, each of length n/2, and the Stan will put them back and return m chains each of length n. I guess that Stan will also return the warmup iterations if you ask it, but usually I don’t do anything with them.

You can get the precise definition we use in both the Stan Reference Manual and in Gelman et al.'s Bayesian Data Analysis (free pdf on the book’s home page). Here’s the relevant section of the Reference Manual: