brms's converters, with brms's arguments and brms's output. The
as_draws_*() family takes variable (exact names unless regex)
and returns a posterior draws object; as_draws() is brms's
as_draws_list(). as.matrix(), as.array() and as.data.frame()
return brms's unclassed objects, with brms's deprecated pars and
subset accepted under brms's own warning.
Usage
# S3 method for class 'frmtmb_draws'
as_draws(x, variable = NULL, regex = FALSE, inc_warmup = FALSE, ...)
# S3 method for class 'frmtmb_draws'
as.data.frame(
x,
row.names = NULL,
optional = TRUE,
pars = NA,
variable = NULL,
draw = NULL,
subset = NULL,
...
)
# S3 method for class 'frmtmb_draws'
as.array(x, pars = NA, variable = NULL, draw = NULL, subset = NULL, ...)
# S3 method for class 'frmtmb_draws'
as_draws_matrix(x, variable = NULL, regex = FALSE, inc_warmup = FALSE, ...)
# S3 method for class 'frmtmb_draws'
as_draws_array(x, variable = NULL, regex = FALSE, inc_warmup = FALSE, ...)
# S3 method for class 'frmtmb_draws'
as_draws_df(x, variable = NULL, regex = FALSE, inc_warmup = FALSE, ...)
# S3 method for class 'frmtmb_draws'
as_draws_list(x, variable = NULL, regex = FALSE, inc_warmup = FALSE, ...)
# S3 method for class 'frmtmb_draws'
as_draws_rvars(x, variable = NULL, regex = FALSE, inc_warmup = FALSE, ...)
as.mcmc(x, ...)
# S3 method for class 'frmtmb_draws'
as.mcmc(
x,
pars = NA,
fixed = FALSE,
combine_chains = FALSE,
inc_warmup = FALSE,
...
)
# S3 method for class 'frmtmb_draws'
as.matrix(x, pars = NA, variable = NULL, draw = NULL, subset = NULL, ...)Arguments
- x
A
frmtmb_drawsobject.- variable
Variables to keep, by exact name unless
regex.- regex
If
TRUE,variableis a regular expression.- inc_warmup
If
TRUE, each chain starts with its warmup iterations, whichfrm_sample()keeps when rstan saved them (save_warmup = TRUE, rstan's default and brms's). Without saved warmup the draws come alone, as in brms. As in brms, it is refused withcombine_chains = TRUEand on thinned draws.- ...
For
as.matrix(),as.array()andas.data.frame(), theregex,fixedandinc_warmupbrms passes on, and theiterationandchainit hands toposterior::subset_draws()(as.array(x, chain = 1)is the first chain); anything else is refused by name, rather than silently changing nothing.- row.names, optional
Accepted for the generic and unused, as in brms.
- pars
Variables to keep, in brms's spelling:
NA(the default) for all of them, otherwise a character vector matched as a regular expression unlessfixed = TRUE. The argument sits in brms's own second position, soas.mcmc(x, TRUE)is refused here exactly as brms refuses it.- draw
Draws to keep, by index.
- subset
brms's deprecated alias of
draw; it warns.- fixed
If
TRUE,parsis matched by exact name.- combine_chains
If
TRUE, onemcmcobject over the pooled draws; otherwise anmcmc.listwith one component per chain, which is what coda's diagnostics (gelman.diag()) need.
Value
A posterior::draws_matrix: one column per sampled variable
and one row per draw.
Examples
# \donttest{
if (requireNamespace("posterior", quietly = TRUE) &&
requireNamespace("tmbstan", quietly = TRUE) &&
requireNamespace("rstan", quietly = TRUE) &&
!frmtmb.sample:::tmbstan_build_broken()) {
set.seed(9)
dd <- data.frame(x = rnorm(80), g = factor(rep(1:8, 10)))
dd$y <- rnorm(80, 1 + 0.5 * dd$x + rnorm(8, 0, 0.5)[dd$g], 1)
fit <- frm(bf(y ~ x + (1 | g)) + gaussian(), data = dd)
ds <- frm_sample(fit, chains = 1, iter = 500, refresh = 0)
# hands the draws to the posterior package, keeping the frmtmb
# parameter names
dm <- as_draws(ds)
posterior::summarise_draws(dm)
# which is what variables() lists
head(variables(ds))
}
#> frm_sample(): default priors (brms 2.23 defaults; prior = "flat" puts brms's (flat) in every slot)
#> Intercept student_t(3, 1, 2.5)
#> sigma student_t(3, 0, 2.5) [natural scale]
#> sd student_t(3, 0, 2.5) [natural sd scale]
#> b (flat), as brms leaves slopes
#> Warning: The largest R-hat is 1.1, indicating chains have not mixed.
#> Running the chains for more iterations may help. See
#> https://mc-stan.org/misc/warnings.html#r-hat
#> Warning: Bulk Effective Samples Size (ESS) is too low, indicating posterior means and medians may be unreliable.
#> Running the chains for more iterations may help. See
#> https://mc-stan.org/misc/warnings.html#bulk-ess
#> Warning: Tail Effective Samples Size (ESS) is too low, indicating posterior variances and tail quantiles may be unreliable.
#> Running the chains for more iterations may help. See
#> https://mc-stan.org/misc/warnings.html#tail-ess
#> [1] "b_Intercept" "b_x" "sigma" "r_g[1,Intercept]"
#> [5] "r_g[2,Intercept]" "r_g[3,Intercept]"
# }