Import certain parameters from cmdstan .csv output files to Stanfit object

Hi everyone,

I am using CmdStan on a Linux machine, but I post-process the output files using R on Windows. Loading the whole output to a Stanfit object with read_stan_csv(files) takes forever, and doing convergence diagnostics with this object even longer. Is there any command or workaround to load only specific parameters from the .csv output files to the R environment?

Thanks in advance.

You can do that using cmdstanr.

cmdstanr::read_cmdstan_csv(variables = "alpha")

For more see:

1 Like

Thanks, that was what I was looking for.

One follow-up question:

files ← c(“output_1.csv”, “output_2.csv”)
mod = read_cmdstan_csv(files, variables = c(“mu”, “nu”))

it writes all the parameters to a list, so using

rstan::traceplot(mod, pars = c(“mu”))

won’t work anymore. Can I extract the csv files still to a Stanfit object?

I dont think you can make a stanfit from that, but you can traceplot from cmdstanr easily.


f <- cmdstanr::read_cmdstan_csv(files, variables = c("mu", "nu"))
bayesplot::mcmc_trace(f$post_warmup_draws[,,c("mu", "nu")])

A different example: