% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/method-update.R
\name{update}
\alias{update}
\alias{update,INLAvaan-method}
\title{Update and re-fit an INLAvaan model}
\usage{
\S4method{update}{INLAvaan}(object, model, add, ..., evaluate = TRUE)
}
\arguments{
\item{object}{An object of class \link{INLAvaan}.}

\item{model}{Optional replacement model, in the same form accepted by
\code{\link[=inlavaan]{inlavaan()}} (lavaan model syntax or a parameter table).}

\item{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 \code{model} is supplied.}

\item{...}{Further arguments passed to \code{\link[=inlavaan]{inlavaan()}}, overriding the values
in the original call (e.g. \code{dp}, \code{marginal_method}, \code{nsamp}, \code{data}).}

\item{evaluate}{Logical. If \code{TRUE} (default) the updated call is evaluated
and the re-fitted \link{INLAvaan} object is returned; if \code{FALSE} the updated,
unevaluated call is returned for inspection.}
}
\value{
A re-fitted \link{INLAvaan} object, or the updated call when
\code{evaluate = FALSE}.
}
\description{
Re-fit an \link{INLAvaan} model with modified arguments, in the style of
\code{\link[stats:update]{stats::update()}}. This is convenient for prior-sensitivity analyses
(vary \code{dp} or the \code{prior()} modifiers), iterative respecification (swap the
\code{model} or \code{add} syntax), and swapping approximation settings (e.g.
\code{marginal_method}, \code{nsamp}) without retyping the whole call.
}
\details{
The method edits the recorded \code{\link[=inlavaan]{inlavaan()}} call, replacing \code{model} (or
extending it via \code{add}) and overriding any argument supplied through \code{...},
then re-evaluates it. Because \link{INLAvaan} extends the \pkg{lavaan} class, a
dedicated method is required: without it, \code{update()} would dispatch to
\pkg{lavaan}'s method and silently return a frequentist \pkg{lavaan} fit
instead of a Bayesian one.

When the parameter structure is preserved (no change to \code{model}, \code{add}, or
\code{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
\code{start} explicitly to override it.

Fits produced by INLAvaan versions that did not record their call cannot be
updated; re-fit once with \code{\link[=inlavaan]{inlavaan()}} (or \code{\link[=acfa]{acfa()}}, \code{\link[=asem]{asem()}}, \code{\link[=agrowth]{agrowth()}})
and \code{update()} will work on the new object.
}
\examples{
\dontrun{
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)
}
}
\seealso{
\code{\link[=inlavaan]{inlavaan()}}, \code{\link[=compare]{compare()}}
}
