Learn R Programming

brms (version 0.9.1)

make_stancode: Stan Code for brms Models

Description

Generate Stan code for brms models

Usage

make_stancode(formula, data = NULL, family = gaussian(), prior = NULL,
  autocor = NULL, nonlinear = NULL, partial = NULL,
  threshold = c("flexible", "equidistant"), sparse = FALSE,
  cov_ranef = NULL, sample_prior = FALSE, stan_funs = NULL,
  save_model = NULL, ...)

Arguments

formula
An object of class "formula" (or one that can be coerced to that class): a symbolic description of the model to be fitted. The details of model specification are given under 'Details'.
data
An optional data frame, list or environment (or object coercible by as.data.frame to a data frame) containing the variables in the model. If not found in data, the variables are taken from environment(formula), typically t
family
A description of the error 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. Currently, the following families are supported: gaussian
prior
One or more brmsprior objects created by function set_prior and combined using the c method. A single brmsprior object may be passed without
autocor
An optional cor_brms object describing the correlation structure within the response variable (i.e. the 'autocorrelation'). See the documentation of cor_brms
nonlinear
An optional list of formuluas, specifying linear models for non-linear parameters. If NULL (the default) formula is treated as an ordinary formula. If not NULL, formula is treated as a non-linear mo
partial
(Deprecated) A one sided formula of the form ~expression allowing to specify predictors with category specific effects in non-cumulative ordinal models (i.e. in families cratio, sratio, or acat).
threshold
A character string indicating the type of thresholds (i.e. intercepts) used in an ordinal model. "flexible" provides the standard unstructured thresholds and "equidistant" restricts the distance between consecutive thresh
sparse
Logical; indicates whether the fixed effects design matrix should be treated as sparse (defaults to FALSE). For design matrices with many zeros, this can considerably reduce required memory. For all models using multivariate syntax (i.
cov_ranef
A list of matrices that are proportional to the (within) covariance structure of the random effects. The names of the matrices should correspond to columns in data that are used as grouping factors. All levels of the grouping factor s
sample_prior
A flag to indicate if samples from all specified proper priors should be drawn additionally to the posterior samples (defaults to FALSE). Among others, these samples can be used to calculate Bayes factors for point hypotheses. Alternat
stan_funs
An optional character string containing self-defined Stan functions, which will be included in the functions block of the generated Stan code.
save_model
Either NULL or a character string. In the latter case, the model code is saved in a file named after the string supplied in save_model, which may also contain the full path where to save the file. If only a name is given, t
...
Other arguments for internal usage only

Value

  • A character string containing the fully commented Stan code to fit a brms model.

Examples

Run this code
make_stancode(rating ~ treat + period + carry + (1|subject), 
              data = inhaler, family = "cumulative")

make_stancode(count ~ log_Age_c + log_Base4_c * Trt_c 
              + (1|patient) + (1|visit), 
              data = epilepsy, family = "poisson")

Run the code above in your browser using DataLab