expose_model_functions.bgmfit {bsitar}R Documentation

Expose User-Defined Stan Functions for Post-Processing

Description

The expose_model_functions() function is a wrapper around rstan::expose_stan_functions() that exposes user-defined Stan function(s). These functions are necessary for post-processing 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 containing the user-defined Stan function(s) in Stan code. If NULL (the default), the scode will be retrieved from the model.

expose

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

select_model

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

returnobj

A logical (default TRUE) to specify whether to return the model object. If expose = TRUE, it is advisable to set returnobj = TRUE.

vectorize

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

verbose

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

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.

...

Additional arguments passed to the rstan::expose_stan_functions() function. The "..." can be used to set the compiler, which can be either rstan::stanc() or rstan::stan_model(). You can also pass other compiler-specific arguments such as save_dso for rstan::stan_model(). Note that while both rstan::stanc() and rstan::stan_model() can be used as compilers before calling rstan::expose_stan_functions(), it is important to note that the execution time for rstan::stan_model() is approximately twice as long as rstan::stanc().

Value

An object of class bgmfit if returnobj = TRUE; otherwise, it returns NULL invisibly.

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 the 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 avoids model compilation that often takes time.

expose_model_functions(model, expose = FALSE)



[Package bsitar version 0.3.2 Index]