R/stan_to_coda.R

#' Stan MCMC to coda
#'
#' Converts the output of a model fitted using rStan to a coda object. This then allows for statistics such as potential scale reduction factor to be computed using the coda library.
#' @param chain The MCMC chain to be converted
#' @export
stan2coda <- function(chain) {
  coda_chain <- coda::mcmc.list(lapply(1:ncol(chain), function(x) coda::mcmc(as.array(chain)[,x,])))
  return(coda_chain)
}
thomaspinder/usefulRFunctions documentation built on May 10, 2019, 8:27 a.m.