Sample a model again with changed sampling arguments
Source:R/methods-draws.R
update.frmtmb_draws.Rdbrms's update() of a fitted model, for the arguments that change
how the model is sampled and not the model itself: sample_prior,
prior, and the sampler's options (chains, iter, seed,
control, ...). It calls frm_sample() again on the same model with
the arguments of the first call, the ones given here replacing them. A
new prior merges as in brms: it takes the slots it names, and the first
call's other specifications stay.
brms's update(fit, sample_prior = "yes") is the common use: it adds
prior draws to a model sampled without them, for
prior_draws() and the evidence ratios of frmtmb::hypothesis().
Usage
# S3 method for class 'frmtmb_draws'
update(object, formula., newdata = NULL, recompile = NULL, ...)Arguments
- object
A
frmtmb_drawsfromfrm_sample().- formula., newdata
brms's arguments for a new model; refused.
- recompile
brms's argument for a new Stan program; frmtmb compiles none, and anything but
NULLis refused.- ...
Arguments of
frm_sample()to change.
Details
A new formula or new data changes the model, which the draws do not
carry in a form that can be revised: update() the fit with them and
call frm_sample() on the result.
Examples
# \donttest{
if (requireNamespace("tmbstan", quietly = TRUE) &&
requireNamespace("rstan", quietly = TRUE) &&
!frmtmb.sample:::tmbstan_build_broken()) {
set.seed(1)
dd <- data.frame(x = rnorm(40))
dd$y <- rnorm(40, 1 + 0.5 * dd$x, 1)
ds <- frm_sample(bf(y ~ x), family = gaussian(), data = dd,
prior = set_prior("normal(0, 1)", class = "b"),
chains = 1, iter = 400, seed = 1, refresh = 0)
ds2 <- update(ds, sample_prior = "yes")
names(prior_draws(ds2))
}
#> frm_sample(): default priors (brms 2.23 defaults; prior = "flat" puts brms's (flat) in every slot)
#> Intercept student_t(3, 1.1, 2.5)
#> sigma student_t(3, 0, 2.5) [natural scale]
#> b (flat), as brms leaves slopes
#> 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
#> frm_sample(): default priors (brms 2.23 defaults; prior = "flat" puts brms's (flat) in every slot)
#> Intercept student_t(3, 1.1, 2.5)
#> sigma student_t(3, 0, 2.5) [natural scale]
#> b (flat), as brms leaves slopes
#> 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
#> [1] "Intercept" "b" "sigma"
# }