R/as-mcarray.R

Defines functions as.mcarray.mcmcarray as.mcarray.mcarray as.mcarray.default as.mcarray

Documented in as.mcarray

#' Coerce to an mcarray object
#'
#' Coerces MCMC objects to an mcarray object.
#'
#' @inheritParams params
#' @param x object to coerce.
#' @family coerce
#' @export
#' @examples
#' as.mcarray(mcmcr_example$beta)
as.mcarray <- function(x, ...) UseMethod("as.mcarray")

#' @export
as.mcarray.default <- function(x, ...) as.mcarray(as.mcmcarray(x))

#' @export
as.mcarray.mcarray <- function(x, ...) x

#' @export
as.mcarray.mcmcarray <- function(x, ...) {
  n <- ndims(x)
  names(dim(x)) <- c("chain", "iteration", rep("", n - 2))
  x <- aperm(x, c(3:n, 2, 1))
  set_class(x, "mcarray")
}

Try the mcmcr package in your browser

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

mcmcr documentation built on Sept. 7, 2021, 1:07 a.m.