| as.array,blimp_obj-method | R Documentation |
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().
## S4 method for signature 'blimp_obj'
as.array(x, warmup = c("exclude", "include", "only"), ...)
x |
A |
warmup |
One of |
... |
Additional arguments (unused). |
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.
A numeric 3-D array with dimensions [iteration, chain, parameter],
named dimnames, and (when warmup = "include") an "n_warmup"
attribute.
as_draws_array.blimp_obj() for the posterior::draws_array
equivalent.
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.