as_draws.blimp_obj: Convert blimp_obj to a posterior draws object

View source: R/blimp_obj_draws.R

as_draws.blimp_objR Documentation

Convert blimp_obj to a posterior draws object

Description

S3 methods for the posterior::as_draws() family of generics, allowing blimp_obj to be used anywhere a posterior::draws object is expected. This is the gateway to the posterior and bayesplot ecosystems: once converted, the usual summarise_draws(), mcmc_trace(), mcmc_areas(), etc., all work.

The posterior package must be installed to use these methods. It is listed in Suggests, so install it explicitly with install.packages("posterior") if needed.

Usage

## S3 method for class 'blimp_obj'
as_draws(x, warmup = c("exclude", "include", "only"), ...)

## S3 method for class 'blimp_obj'
as_draws_array(x, warmup = c("exclude", "include", "only"), ...)

## S3 method for class 'blimp_obj'
as_draws_df(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

All three methods accept a warmup argument with the same semantics as as.array,blimp_obj-method. Because draws_array objects do not carry a separate warmup/sampling distinction, the "n_warmup" attribute set by as.array(x, warmup = "include") is dropped during conversion; users who need the warmup marker should convert via as.array() and pass the result to bayesplot::mcmc_trace() directly.

Value

An object of class posterior::draws_array (for as_draws and as_draws_array) or posterior::draws_df (for as_draws_df).

Examples


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')
)
model <- rblimp(
    list(structure = 'y ~ f', measurement = 'f -> x1:x5'),
    mydata,
    chains = 4,
    seed = 3927,
    latent = ~ f
)

draws <- posterior::as_draws_array(model)
posterior::summarise_draws(draws)

## Not run: 
if (requireNamespace("bayesplot", quietly = TRUE)) {
    bayesplot::mcmc_trace(draws)
    bayesplot::mcmc_areas(draws)
}

## End(Not run)


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