Make a Stanfit object from cmdstan output files

I recently moved from Rstan to cmdstan and I’m still trying to optimize my workflow acordingly.

Usually I imported the .csv output files from cmdstan using

files = c("output_1.csv", "output_2.csv")
out <- rstan:::read_stan_csv(files)

Because my output files are quite large, I like that the cmdstanr::read_cmdstan_csv command allows to select certain variables to import:

files = c("output_1.csv", "output_2.csv")
out <- cmdstanr::read_cmdstan_csv(files, variables = "alpha")

However, I normally post-processed the posterior output using Stanfit objects. So my questions are:

  • Can I transform the list generated through the cmdstanr::read_cmdstan_csv to a Stanfit object?
  • If not, is there any documentation on how to access the elements of this list for certain operations (e.g., get the mean of a parameter across all draws, do traceplots, …)?

Thanks in advance.

1 Like

I recommend you use the posterior package, which would mean you can skip the step of conversion to a rstan::stanfit object.