R/MCMCsummary.R

Defines functions MCMCsummary

Documented in MCMCsummary

#' The cleanest summary for mcmc.list object
#'
#' A function to report the summary table of mcmc object
#' @param mcmcObj mcmc.list object
#' @importFrom  coda gelman.diag
#' @export
#'
#'

MCMCsummary <- function(mcmcObj) {
  stopifnot(class(mcmcObj) == "mcmc.list")

  res = data.frame(
    cbind(round(summary(mcmcObj)$statistics[,1:2], 4),    # Posterior Mean and SD
          round(summary(mcmcObj)$quantiles[,c(1,5)], 4)), # Posterior Percentile 2.5% and 97.5%
    Rhat = gelman.diag(mcmcObj, multivariate = FALSE)[[1]][,1], check.names = FALSE)
  return(res)
}
JihongZ/usefulR documentation built on Sept. 14, 2023, 6:09 p.m.