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:
Using
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.
Example:
f <- cmdstanr::read_cmdstan_csv(files, variables = c("mu", "nu"))
bayesplot::mcmc_trace(f$post_warmup_draws[,,c("mu", "nu")])
A different example:
I am not sure how you can do that with rstanās functions but this work for cmdstan output and traceplots:
# install.packages("remotes")
remotes::install_github("stan-dev/cmdstanr")
library(cmdstanr)
library(bayesplot)
fit <- as_cmdstan_fit(files)
color_scheme_set("mix-blue-pink")
mcmc_trace(fit$draws(variables = c("alpha", "beta[1]")))
[image]