R/mcmc_traces_fit.R

Defines functions mcmcTraces

Documented in mcmcTraces

#' Traces of MCMC iterations
#' 
#' @param fit An object of class \code{fitTK}
#' @param plots A string selecting the parameters. Defaults is \code{"all"} and select all parameters.
#' Deterministc parameters can be selected by setting \code{"deterministic"} and 
#' stochastic parameter with \code{"stochastic"}
#'
#' @return A traceplot of class \code{ggplot}.
#' 
#' @export
#'
mcmcTraces <- function(fit, plots = "all"){
  if (plots == "deterministic"){
    corr <- ggmcmc::ggs(fit[["stanfit"]], family = "^k|^g")
  } else if (plots == "stochastic") {
    corr <- ggmcmc::ggs(fit[["stanfit"]], family = "^sigma")
  } else {
    corr <- ggmcmc::ggs(fit[["stanfit"]], family = "^k|^g|^sigma")
  }
  plots <- ggmcmc::ggs_traceplot(corr, greek = TRUE) +
    scale_colour_manual(values = alpha(c("#333333", "#ee7202", "#63ad00", "#333333"), 1)) +
    theme(legend.title = element_blank())
  
  return(plots)
}

Try the rbioacc package in your browser

Any scripts or data that you put into this service are public.

rbioacc documentation built on Sept. 21, 2023, 5:06 p.m.