#' @title Dimensions of MCMC objects
#'
#' @description Retrieve dimensions of an MCMC object:
#' * `n_chain(x)` the number of chains
#' * `n_var(x)` the number of variables
#' * `n_iter(x)` the number of iterations
#'
#' @details This is similar to `coda::nchain()` but more general, working for
#' the following classes:
#' * `mcmc`
#' * `mcmc.list`
#' * `data.table` (generated by `mcmc_to_dt`)
#' * `stanfit`
#' * `jags`
#'
#' @param x an mcmc object, see "Details" for a list of supported mcmc objects.
#'
#' @name mcmc-dims
#'
#' @export
n_chain <- function(x){
UseMethod("n_chain")
}
#' @export
n_chain.default <- function(x){
stop_not_right_for_mmcc()
}
#' @export
n_chain.mcmc <- function(x){
# if is.mcmc(x) 1
1L
}
#' @export
n_chain.mcmc.list <- function(x){
# if is.mcmc.list length(x)
length(x)
# need to protect against length(0)?
}
#' @export
n_chain.NULL <- function(x){
NULL
}
#' @export
n_chain.data.table <- function(x){
max(x$chain)
}
#' @export
n_chain.stanfit <- function(x){
as.integer(x@sim$chains)
}
#' @export
n_chain.jags <- function(x){
x$nchain()
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.