Adds a new model spec to the hbsaems model registry so that it
can be used by hbm and the flexible factory
hbm_flex. Useful for extending the package with new
likelihoods (e.g.\ Gamma, Tweedie, Skew-Normal),
new link functions, or new auxiliary-parameter hyperpriors without
modifying hbsaems source.
Usage
register_hbsae_model(
key,
family,
link = "identity",
discrete = FALSE,
supports_mi = !discrete,
has_addition_term = FALSE,
addition_template = NULL,
response_check = function(y) TRUE,
response_check_msg = NULL,
default_priors = function(...) NULL,
aux_param_hyperprior = NULL,
overwrite = FALSE
)Arguments
- key
Character. Unique identifier (e.g.\
"gamma_log").- family
Character. The brms family name passed to
hb_sampling.- link
Character. Default link function (default
"identity").- discrete
Logical. Is the response discrete? Affects whether
handle_missing = "model"(joint Bayesian imputation viabrms::mi()) is allowed (defaultFALSE).- supports_mi
Logical. Whether
brms::mi()can impute the response variable for this family (default!discrete).- has_addition_term
Logical. Whether the LHS uses an addition term such as
|\ trials(n)(defaultFALSE).- addition_template
Character. An
sprintftemplate used whenhas_addition_term = TRUE. Must contain three%sslots for response, addition variable, and RHS. Example:"%s | trials(%s) ~ %s".- response_check
Function
function(y)returningTRUEwhen the response domain is valid,FALSEotherwise (default: accept anything).- response_check_msg
Character. Error message displayed when
response_check(y)returnsFALSE.- default_priors
Function
function(...)returning abrmspriorobject, orNULLto use brms defaults.- aux_param_hyperprior
Optional function
function(args, data)returning a list with componentsprior(abrmsprior) andstanvars(astanvarobject). Used by distributions that have an auxiliary parameter (e.g.\ \(\phi\) for Beta, shape for Gamma) requiring a hyperprior expressed in raw Stan code. Theargslist contains family-specific user inputs forwarded throughaux_argsinhbm_flex. ReturnNULLto skip injection for a given call.- overwrite
Logical. Permit overwriting an existing key (default
FALSE).
Details
After registering, you can fit a model directly with
hbm_flex:
register_hbsae_model(
key = "gamma_log",
family = "Gamma",
link = "log",
discrete = FALSE,
supports_mi = TRUE,
response_check = function(y) all(y > 0, na.rm = TRUE),
response_check_msg = "Gamma response must be strictly positive."
)
fit <- hbm_flex(
family_key = "gamma_log",
response = "expenditure",
auxiliary = c("x1", "x2"),
data = my_data
)