| update | R Documentation |
Re-fit an INLAvaan model with modified arguments, in the style of
stats::update(). This is convenient for prior-sensitivity analyses
(vary dp or the prior() modifiers), iterative respecification (swap the
model or add syntax), and swapping approximation settings (e.g.
marginal_method, nsamp) without retyping the whole call.
## S4 method for signature 'INLAvaan'
update(object, model, add, ..., evaluate = TRUE)
object |
An object of class INLAvaan. |
model |
Optional replacement model, in the same form accepted by
|
add |
Optional lavaan syntax appended to the original model. Requires
the original model to have been specified as a syntax string, and is
ignored when |
... |
Further arguments passed to |
evaluate |
Logical. If |
The method edits the recorded inlavaan() call, replacing model (or
extending it via add) and overriding any argument supplied through ...,
then re-evaluates it. Because INLAvaan extends the lavaan class, a
dedicated method is required: without it, update() would dispatch to
lavaan's method and silently return a frequentist lavaan fit
instead of a Bayesian one.
When the parameter structure is preserved (no change to model, add, or
model.type), the previous posterior mode is passed as the optimiser's
starting value (a warm start), so mode-finding is typically much faster than
a cold fit. This makes prior sweeps particularly cheap. The warm start only
changes the optimiser's starting point, not the fitted result. Supply
start explicitly to override it.
Fits produced by INLAvaan versions that did not record their call cannot be
updated; re-fit once with inlavaan() (or acfa(), asem(), agrowth())
and update() will work on the new object.
A re-fitted INLAvaan object, or the updated call when
evaluate = FALSE.
inlavaan(), compare()
## Not run:
model <- "visual =~ x1 + x2 + x3"
fit <- acfa(model, data = lavaan::HolzingerSwineford1939)
# Prior sensitivity: refit under a tighter loading prior (warm-started)
fit2 <- update(fit, dp = priors_for(lambda = "normal(0,1)"))
# Respecify: add a residual covariance
fit3 <- update(fit, add = "x1 ~~ x2")
compare(fit, fit3)
# Swap approximation settings only
fit4 <- update(fit, marginal_method = "sampling", nsamp = 4000)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.