Generate Stan code for brms models
make_stancode(formula, data, family = gaussian(), prior = NULL,
autocor = NULL, cov_ranef = NULL, sparse = FALSE,
sample_prior = c("no", "yes", "only"), stan_funs = NULL,
save_model = NULL, silent = FALSE, ...)
An object of class
formula
,
brmsformula
, or mvbrmsformula
(or one that can be coerced to that classes):
A symbolic description of the model to be fitted.
The details of model specification are explained in
brmsformula
.
An object of class data.frame
(or one that can be coerced to that class)
containing data of all variables used in the model.
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 link
argument allowing to specify
the link function to be applied on the response variable.
If not specified, default links are used.
For details of supported families see
brmsfamily
.
By default, a linear gaussian
model is applied.
In multivariate models, family
might also be a list of families.
An optional cor_brms
object describing
the correlation structure within the response variable
(i.e., the 'autocorrelation').
See the documentation of cor_brms
for a description
of the available correlation structures. Defaults to NULL
,
corresponding to no correlations.
In multivariate models, autocor
might also be a list
of autocorrelation structures.
A list of matrices that are proportional to the
(within) covariance structure of the group-level effects.
The names of the matrices should correspond to columns
in data
that are used as grouping factors.
All levels of the grouping factor should appear as rownames
of the corresponding matrix. This argument can be used,
among others to model pedigrees and phylogenetic effects.
See vignette("brms_phylogenetics")
for more details.
Logical; indicates whether the population-level
design matrices should be treated as sparse (defaults to FALSE
).
For design matrices with many zeros, this can considerably
reduce required memory. Sampling speed is currently not
improved or even slightly decreased.
Indicate if samples from all specified
proper priors should be drawn additionally to the posterior samples
(defaults to "no"
). Among others, these samples can be used
to calculate Bayes factors for point hypotheses.
If set to "only"
, samples are drawn solely from
the priors ignoring the likelihood. In this case,
all parameters must have proper priors.
An optional character string containing self-defined Stan functions, which will be included in the functions block of the generated Stan code. Note that these functions must additionally be defined as vectorized R functions in the global environment for various post-processing methods to work on the returned model object.
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, the file is saved in the current working directory.
logical; If TRUE
, warnings of
the Stan parser will be suppressed.
Other arguments for internal usage only
A character string containing the fully commented Stan code to fit a brms model.
# NOT RUN {
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