Title: | Bindings for Bayesian TidyModels |
---|---|
Description: | Fit Bayesian models using 'brms'/'Stan' with 'parsnip'/'tidymodels' via 'bayesian' <doi:10.5281/zenodo.4426836>. 'tidymodels' is a collection of packages for machine learning; see Kuhn and Wickham (2020) <https://www.tidymodels.org>). The technical details of 'brms' and 'Stan' are described in Bürkner (2017) <doi:10.18637/jss.v080.i01>, Bürkner (2018) <doi:10.32614/RJ-2018-017>, and Carpenter et al. (2017) <doi:10.18637/jss.v076.i01>. |
Authors: | Hamada S. Badr [aut, cre] , Paul-Christian Bürkner [aut] |
Maintainer: | Hamada S. Badr <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.0.1 |
Built: | 2025-01-06 13:18:13 UTC |
Source: | https://github.com/hsbadr/bayesian |
bayesian()
is a way to generate a specification of a model
before fitting and allows the model to be created using
Stan via brms package in R.
bayesian( mode = "regression", engine = "brms", formula.override = NULL, family = NULL, prior = NULL, sample_prior = NULL, knots = NULL, stanvars = NULL, fit = NULL, init = NULL, chains = NULL, iter = NULL, warmup = NULL, thin = NULL, cores = NULL, threads = NULL, algorithm = NULL, backend = NULL, stan_args = NULL, control = NULL, save_pars = NULL, save_model = NULL, file = NULL, file_refit = NULL, normalize = NULL, future = NULL, seed = NULL, silent = NULL ) ## S3 method for class 'bayesian' update( object, parameters = NULL, formula.override = NULL, family = NULL, prior = NULL, sample_prior = NULL, knots = NULL, stanvars = NULL, fit = NULL, init = NULL, chains = NULL, iter = NULL, warmup = NULL, thin = NULL, cores = NULL, threads = NULL, algorithm = NULL, backend = NULL, stan_args = NULL, control = NULL, save_pars = NULL, save_model = NULL, file = NULL, file_refit = NULL, normalize = NULL, future = NULL, seed = NULL, silent = NULL, fresh = FALSE, ... ) bayesian_fit(formula, data, ...) bayesian_formula(formula, ...) bayesian_terms(formula, ...) bayesian_family(family, ...) bayesian_predict(object, ...) bayesian_write(object, file) bayesian_read(file)
bayesian( mode = "regression", engine = "brms", formula.override = NULL, family = NULL, prior = NULL, sample_prior = NULL, knots = NULL, stanvars = NULL, fit = NULL, init = NULL, chains = NULL, iter = NULL, warmup = NULL, thin = NULL, cores = NULL, threads = NULL, algorithm = NULL, backend = NULL, stan_args = NULL, control = NULL, save_pars = NULL, save_model = NULL, file = NULL, file_refit = NULL, normalize = NULL, future = NULL, seed = NULL, silent = NULL ) ## S3 method for class 'bayesian' update( object, parameters = NULL, formula.override = NULL, family = NULL, prior = NULL, sample_prior = NULL, knots = NULL, stanvars = NULL, fit = NULL, init = NULL, chains = NULL, iter = NULL, warmup = NULL, thin = NULL, cores = NULL, threads = NULL, algorithm = NULL, backend = NULL, stan_args = NULL, control = NULL, save_pars = NULL, save_model = NULL, file = NULL, file_refit = NULL, normalize = NULL, future = NULL, seed = NULL, silent = NULL, fresh = FALSE, ... ) bayesian_fit(formula, data, ...) bayesian_formula(formula, ...) bayesian_terms(formula, ...) bayesian_family(family, ...) bayesian_predict(object, ...) bayesian_write(object, file) bayesian_read(file)
mode |
A single character string for the prediction outcome mode. Possible values for this model are "unknown", "regression", or "classification". |
engine |
A single character string specifying what computational
engine to use for fitting. Possible engines are listed below.
The default for this model is |
formula.override |
Overrides the formula; for details see
|
family |
A description of the response distribution and link function to
be used in the model. This can be a family function, a call to a family
function or a character string naming the family. Every family function has
a |
prior |
One or more |
sample_prior |
Indicate if draws from priors should be drawn
additionally to the posterior draws. Options are |
knots |
Optional list containing user specified knot values to be used
for basis construction of smoothing terms. See
|
stanvars |
An optional |
fit |
An instance of S3 class |
init |
Initial values for the sampler. If |
chains |
Number of Markov chains (defaults to 4). |
iter |
Number of total iterations per chain (including warmup; defaults to 2000). |
warmup |
A positive integer specifying number of warmup (aka burnin)
iterations. This also specifies the number of iterations used for stepsize
adaptation, so warmup draws should not be used for inference. The number
of warmup should not be larger than |
thin |
Thinning rate. Must be a positive integer. Set |
cores |
Number of cores to use when executing the chains in parallel,
which defaults to 1 but we recommend setting the |
threads |
Number of threads to use in within-chain parallelization. For
more control over the threading process, |
algorithm |
Character string naming the estimation approach to use.
Options are |
backend |
Character string naming the package to use as the backend for
fitting the Stan model. Options are |
stan_args |
A list of extra arguments to Stan. |
control |
A named |
save_pars |
An object generated by |
save_model |
Either |
file |
A character string of the file path to |
file_refit |
Modifies when the fit stored via the |
normalize |
Logical. Indicates whether normalization constants should
be included in the Stan code (defaults to |
future |
Logical; If |
seed |
The seed for random number generation to make results
reproducible. If |
silent |
Verbosity level between |
object |
A Bayesian model specification. |
parameters |
A 1-row tibble or named list with main
parameters to update. If the individual arguments are used,
these will supersede the values in |
fresh |
A logical for whether the arguments should be modified in-place of or replaced wholesale. |
... |
Other arguments passed to internal functions. |
formula |
An object of class |
data |
An object of class |
The arguments are converted to their specific names at the
time that the model is fit. Other options and argument can be
set using set_engine()
. If left to their defaults
here (NULL
), the values are taken from the underlying model
functions. If parameters need to be modified, update()
can be
used in lieu of recreating the object from scratch.
The data given to the function are not saved and are only used
to determine the mode of the model. For bayesian()
, the
possible modes are "regression" and "classification".
The model can be created by the fit()
function using the
following engines:
brms: "brms"
An updated model specification.
Engines may have pre-set default arguments when executing the model fit call. For this type of model, the template of the fit calls are:
bayesian() |> set_engine("brms") |> translate()
## Bayesian Model Specification (regression) ## ## Computational engine: brms ## ## Model fit template: ## bayesian::bayesian_fit(formula = missing_arg(), data = missing_arg(), ## weights = missing_arg())
brm
,
brmsfit
,
update.brmsfit
,
predict.brmsfit
,
posterior_epred.brmsfit
,
posterior_predict.brmsfit
,
brmsformula
,
brmsformula-helpers
,
brmsterms
,
brmsfamily
,
customfamily
,
family
,
formula
,
update.formula
.
bayesian() show_model_info("bayesian") bayesian(mode = "classification") bayesian(mode = "regression") ## Not run: bayesian_mod <- bayesian() |> set_engine("brms") |> fit( rating ~ treat + period + carry + (1 | subject), data = inhaler ) summary(bayesian_mod$fit) ## End(Not run) model <- bayesian(init = "random") model update(model, init = "0") update(model, init = "0", fresh = TRUE)
bayesian() show_model_info("bayesian") bayesian(mode = "classification") bayesian(mode = "regression") ## Not run: bayesian_mod <- bayesian() |> set_engine("brms") |> fit( rating ~ treat + period + carry + (1 | subject), data = inhaler ) summary(bayesian_mod$fit) ## End(Not run) model <- bayesian(init = "random") model update(model, init = "0") update(model, init = "0", fresh = TRUE)