expose_model_functions.bgmfit {bsitar}R Documentation

Expose user defined Stan function for post-processing

Description

The expose_model_functions() is a wrapper around the rstan::expose_stan_functions() to expose user defined Stan function(s). These exposed functions are needed during the post-processing of the posterior draws.

Usage

## S3 method for class 'bgmfit'
expose_model_functions(
  model,
  scode = NULL,
  expose = TRUE,
  select_model = NULL,
  returnobj = TRUE,
  vectorize = FALSE,
  verbose = FALSE,
  envir = NULL,
  ...
)

expose_model_functions(model, ...)

Arguments

model

An object of class bgmfit.

scode

A character string (Stan code) containing the user-defined Stan function(s). If NULL (default), the scode is retrieved from the model.

expose

A logical (default TRUE) to indicate whether to expose functions and add them to the model as an attribute.

select_model

A character string (default NULL) to indicate the model name. This is for internal use only.

returnobj

A logical (default TRUE) to indicate whether to return the model object. When expose = TRUE, then it is advisable to set returnobj = TRUE too.

vectorize

A logical (default FALSE) to indicate whether the exposed functions should be vectorized via base::Vectorize(). Note that currently vectorize should be set to FALSE because setting it TRUE may not work as expected.

verbose

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

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.

...

Additional arguments passed to the rstan::expose_stan_functions() function.

Value

An object of class bgmfit if returnobj=TRUE, otherwise invisible NULL.

Author(s)

Satpal Sandhu satpal.sandhu@bristol.ac.uk

See Also

rstan::expose_stan_functions()

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

# To save time, argument expose is set as FALSE which runs a dummy test 
# and avoid model compilation which often takes time

expose_model_functions(model, expose = FALSE)



[Package bsitar version 0.2.1 Index]