% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/blimp_obj_draws.R
\name{as.array,blimp_obj-method}
\alias{as.array,blimp_obj-method}
\title{Convert blimp_obj to a 3-D MCMC array}
\usage{
\S4method{as.array}{blimp_obj}(x, warmup = c("exclude", "include", "only"), ...)
}
\arguments{
\item{x}{A \code{blimp_obj} object.}

\item{warmup}{One of \code{"exclude"}, \code{"include"}, or \code{"only"}. Default
\code{"exclude"}.}

\item{...}{Additional arguments (unused).}
}
\value{
A numeric 3-D array with dimensions \verb{[iteration, chain, parameter]},
named \code{dimnames}, and (when \code{warmup = "include"}) an \code{"n_warmup"}
attribute.
}
\description{
Reshapes the MCMC draws in a \code{blimp_obj} into a 3-D numeric array with
dimensions \verb{[iteration, chain, parameter]}. This is the format consumed
directly by \verb{bayesplot::mcmc_*} functions and by \code{\link[posterior:draws_array]{posterior::as_draws_array()}}.
}
\details{
The \code{warmup} argument controls whether burn-in draws are included:
\describe{
\item{\code{"exclude"}}{(default) returns only post-burn sampling draws.}
\item{\code{"include"}}{returns warmup draws stacked on top of sampling
draws within each chain. The returned array carries an
\code{"n_warmup"} attribute giving the number of warmup iterations, so
it can be piped directly into
\code{bayesplot::mcmc_trace(arr, n_warmup = attr(arr, "n_warmup"))}.}
\item{\code{"only"}}{returns only warmup draws.}
}
}
\examples{
\dontshow{if (has_blimp()) withAutoprint(\{ # examplesIf}
# Generate Data with `rblimp_sim`
mydata <- rblimp_sim(
    c(
        'f ~ normal(0, 1)',
        'x1:x5 ~ normal(f, 1)',
        'y ~ normal(10 + 0.3*f, 1 - .3^2)'
    ),
    n = 500,
    seed = 19723,
    variables = c('y', 'x1:x5')
)

# Fit model
model <- rblimp(
    list(structure = 'y ~ f', measurement = 'f -> x1:x5'),
    mydata,
    chains = 4,
    seed = 3927,
    latent = ~ f
)

# Post-burn only (default)
arr <- as.array(model)
dim(arr)
dimnames(arr)$parameters

# Include warmup, feed to bayesplot with its n_warmup marker
\dontrun{
if (requireNamespace("bayesplot", quietly = TRUE)) {
    arr_full <- as.array(model, warmup = "include")
    bayesplot::mcmc_trace(arr_full, n_warmup = attr(arr_full, "n_warmup"))
}
}
\dontshow{\}) # examplesIf}
}
\seealso{
\code{\link[=as_draws_array.blimp_obj]{as_draws_array.blimp_obj()}} for the \link[posterior:draws_array]{posterior::draws_array}
equivalent.
}
