update_model.bgmfit {bsitar}R Documentation

Update model

Description

The update_model() function is a wrapper around the update() function from the brms package, which refits the model based on the user-specified updated arguments.

Usage

## S3 method for class 'bgmfit'
update_model(
  model,
  newdata = NULL,
  recompile = NULL,
  expose_function = FALSE,
  verbose = FALSE,
  check_newargs = FALSE,
  envir = NULL,
  ...
)

update_model(model, ...)

Arguments

model

An object of class bgmfit.

newdata

An optional data.frame to be used when updating the model. If NULL (default), the data used in the original model fit is reused. Note that data-dependent default priors are not automatically updated.

recompile

A logical value indicating whether the Stan model should be recompiled. When NULL (default), update_model() tries to internally determine whether recompilation is required. Setting recompile to FALSE will ignore any changes in the Stan code.

expose_function

A logical argument (default FALSE) to indicate whether Stan functions should be exposed. If TRUE, any Stan functions exposed during the model fit using expose_function = TRUE in the bsitar() function are saved and can be used in post-processing. By default, expose_function = FALSE in post-processing functions, except in optimize_model() where it is set to NULL. If NULL, the setting is inherited from the original model fit. It must be set to TRUE when adding fit criteria or bayes_R2 during model optimization.

verbose

A logical argument (default FALSE) to specify whether to print information collected during the setup of the object(s).

check_newargs

A logical value (default FALSE) indicating whether to check if the arguments in the original model fit and the update_model are identical. When check_newargs = TRUE and the arguments are identical, it indicates that an update is unnecessary. In this case, the original model object is returned, along with a message if verbose = TRUE.

envir

The environment used for function evaluation. The default is NULL, which sets the environment to parent.frame(). Since most post-processing functions rely on brms, it is recommended to set envir = globalenv() or envir = .GlobalEnv, especially for derivatives like velocity curves.

...

Other arguments passed to [brms::brm()].

Details

This function is an adapted version of the update() function from the brms package.

Value

An updated object of class brmsfit.

Author(s)

Satpal Sandhu satpal.sandhu@bristol.ac.uk

Examples




# Fit Bayesian SITAR model 

# To avoid mode estimation which takes time, the Bayesian SITAR model fit to 
# the 'berkeley_exdata' has been saved as an example fit ('berkeley_exfit').
# See 'bsitar' function for details on 'berkeley_exdata' and 'berkeley_exfit'.

# Check and confirm whether model fit object 'berkeley_exfit' exists
 berkeley_exfit <- getNsObject(berkeley_exfit)

model <- berkeley_exfit

# Update model
# Note that in case all arguments supplied to the update_model() call are 
# same as the original model fit (checked via check_newargs = TRUE), then  
# original model object is returned.   
# To explicitly get this information whether model is being updated or not, 
# user can set verbose = TRUE. The verbose = TRUE also useful in getting the
# information regarding what all arguments have been changed as compared to
# the original model.

model2 <- update_model(model, df = 5, check_newargs = TRUE, verbose = TRUE)




[Package bsitar version 0.3.2 Index]