Update an existing bmm mode. This function calls
brms::update.brmsfit(), but it applies the necessary bmm postprocessing
to the model object before and after the update.
Usage
# S3 method for class 'bmmfit'
update(
object,
formula.,
newdata = NULL,
recompile = NULL,
file = NULL,
file_compress = TRUE,
...
)Arguments
- object
An object of class
bmmfit- formula.
A
bmmformula(). If missing, the original formula is used. Currently you have to specify a fullbmmformula- newdata
An optional data frame containing the variables in the model
- recompile
Logical, indicating whether the Stan model should be recompiled. If NULL (the default), update tries to figure out internally, if recompilation is necessary. Setting it to FALSE will cause all Stan code changing arguments to be ignored.
- file
Either
NULLor a character string. If a string, the updated model is saved via saveRDS in a file named after the string, as inbmm().update()never writes to the file the original fit was read from: passfileexplicitly to save the updated fit.- file_compress
Logical or a character string, specifying one of the compression algorithms supported by saveRDS when saving the updated model object.
- ...
Further arguments passed to
brms::update.brmsfit()
Value
An updated bmmfit object refit to the new data and/or formula. If
file is given, it names the newly written file. If not, the file field
is carried over from the original fit, so the updated object still points
at the file it came from – but that file is not rewritten: it still
holds the fit as it was before this update. Pass file to save the
updated fit.
Details
When updating a brmsfit created with the cmdstanr backend in a different R session, a recompilation will be triggered because by default, cmdstanr writes the model executable to a temporary directory. To avoid that, set option "cmdstanr_write_stan_file_dir" to a nontemporary path of your choice before creating the original bmmfit.
For more information and examples, see brms::update.brmsfit()
Examples
if (FALSE) { # isTRUE(Sys.getenv("BMM_EXAMPLES"))
# generate artificial data from the Signal Discrimination Model
# generate artificial data from the Signal Discrimination Model
dat <- data.frame(y = rsdm(2000))
# define formula
ff <- bmf(c ~ 1, kappa ~ 1)
# fit the model
fit <- bmm(
formula = ff,
data = dat,
model = sdm(resp_error = "y"),
cores = 4,
backend = "cmdstanr"
)
# update the model
fit <- update(fit, newdata = data.frame(y = rsdm(2000, kappa = 5)))
}
