update_model.bgmfit {bsitar}R Documentation

Update model

Description

The update_model() is a wrapper around the update() function in the brms package which refits the model as per 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 re used. Note that data-dependent default priors are not updated automatically.

recompile

A logical to indicate whether the Stan model should be recompiled. When NULL (default), update_model() tries to figure out internally whether recompilation is required or not. Setting recompile to FALSE will ignore Stan code changing arguments.

expose_function

An optional logical argument to indicate whether to expose Stan functions (default FALSE). Note that if user has already exposed Stan functions during model fit by setting expose_function = TRUE in the bsitar(), then those exposed functions are saved and can be used during post processing of the posterior draws and therefore expose_function is by default set as FALSE in all post processing functions except optimize_model(). For optimize_model(), the default setting is expose_function = NULL. The reason is that each optimized model has different Stan function and therefore it need to be re exposed and saved. The expose_function = NULL implies that the setting for expose_function is taken from the original model fit. Note that expose_function must be set to TRUE when adding fit criteria and/or bayes_R2 during model optimization.

verbose

An optional argument (logical, default FALSE) to indicate whether to print information collected during setting up the object(s).

check_newargs

A logical (default FALSE) to check whether arguments in the original model fit and the update_model are same. When check_newargs = TRUE and arguments are same, it implies that update is not needed and hence the original model object is returned along with the message if verbose = TRUE.

envir

Environment used for function evaluation. The default is NULL which will set parent.frame() as default environment. Note that since most of post processing functions are based on brms, the functions needed for evaluation should be in the .GlobalEnv. Therefore, it is strongly recommended to set envir = globalenv() (or envir = .GlobalEnv). This is particularly true for the derivatives such as velocity curve.

...

Other arguments passed to brms.

Details

This is an adapted version of the update() function from available the thebrms 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.2.1 Index]