as.array-blimp_obj-method: Convert blimp_obj to a 3-D MCMC array

as.array,blimp_obj-methodR Documentation

Convert blimp_obj to a 3-D MCMC array

Description

Reshapes the MCMC draws in a blimp_obj into a 3-D numeric array with dimensions ⁠[iteration, chain, parameter]⁠. This is the format consumed directly by ⁠bayesplot::mcmc_*⁠ functions and by posterior::as_draws_array().

Usage

## S4 method for signature 'blimp_obj'
as.array(x, warmup = c("exclude", "include", "only"), ...)

Arguments

x

A blimp_obj object.

warmup

One of "exclude", "include", or "only". Default "exclude".

...

Additional arguments (unused).

Details

The warmup argument controls whether burn-in draws are included:

"exclude"

(default) returns only post-burn sampling draws.

"include"

returns warmup draws stacked on top of sampling draws within each chain. The returned array carries an "n_warmup" attribute giving the number of warmup iterations, so it can be piped directly into bayesplot::mcmc_trace(arr, n_warmup = attr(arr, "n_warmup")).

"only"

returns only warmup draws.

Value

A numeric 3-D array with dimensions ⁠[iteration, chain, parameter]⁠, named dimnames, and (when warmup = "include") an "n_warmup" attribute.

See Also

as_draws_array.blimp_obj() for the posterior::draws_array equivalent.

Examples


# 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
## Not run: 
if (requireNamespace("bayesplot", quietly = TRUE)) {
    arr_full <- as.array(model, warmup = "include")
    bayesplot::mcmc_trace(arr_full, n_warmup = attr(arr_full, "n_warmup"))
}

## End(Not run)


rblimp documentation built on May 18, 2026, 9:07 a.m.