# make_stancode

##### Stan Code for brms Models

Generate Stan code for brms models

##### Usage

```
make_stancode(
formula,
data,
family = gaussian(),
prior = NULL,
autocor = NULL,
cov_ranef = NULL,
sparse = NULL,
sample_prior = "no",
stanvars = NULL,
stan_funs = NULL,
knots = NULL,
threads = NULL,
save_model = NULL,
...
)
```

##### Arguments

- formula
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`

.- data
An object of class

`data.frame`

(or one that can be coerced to that class) containing data of all variables used in the model.- 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

`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.- prior
One or more

`brmsprior`

objects created by`set_prior`

or related functions and combined using the`c`

method or the`+`

operator. See also`get_prior`

for more help.- autocor
(Deprecated) 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. It is now recommend to specify autocorrelation terms directly within`formula`

. See`brmsformula`

for more details.- cov_ranef
(Deprecated) 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. It is now recommended to specify those matrices in the formula interface using the`gr`

and related functions. See`vignette("brms_phylogenetics")`

for more details.- sparse
(Deprecated) 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. It is now recommended to use the`sparse`

argument of`brmsformula`

and related functions.- sample_prior
Indicate if samples from priors should be drawn additionally to the posterior samples. Options are

`"no"`

(the default),`"yes"`

, and`"only"`

. Among others, these samples can be used to calculate Bayes factors for point hypotheses via`hypothesis`

. Please note that improper priors are not sampled, including the default improper priors used by`brm`

. See`set_prior`

on how to set (proper) priors. Please also note that prior samples for the overall intercept are not obtained by default for technical reasons. See`brmsformula`

how to obtain prior samples for the intercept. If`sample_prior`

is set to`"only"`

, samples are drawn solely from the priors ignoring the likelihood, which allows among others to generate samples from the prior predictive distribution. In this case, all parameters must have proper priors.- stanvars
An optional

`stanvars`

object generated by function`stanvar`

to define additional variables for use in Stan's program blocks.- stan_funs
(Deprecated) An optional character string containing self-defined Stan functions, which will be included in the functions block of the generated Stan code. It is now recommended to use the

`stanvars`

argument for this purpose instead.- knots
Optional list containing user specified knot values to be used for basis construction of smoothing terms. See

`gamm`

for more details.- threads
Number of threads to use in within-chain parallelization. For more control over the threading process,

`threads`

may also be a`brmsthreads`

object created by`threading`

. Within-chain parallelization is experimental! We recommend its use only if you are experienced with Stan's`reduce_sum`

function and have a slow running model that cannot be sped up by any other means.- save_model
Either

`NULL`

or a character string. In the latter case, the model's Stan code is saved via`cat`

in a text file named after the string supplied in`save_model`

.- ...
Other arguments for internal usage only.

##### Value

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

##### Examples

```
# NOT RUN {
make_stancode(rating ~ treat + period + carry + (1|subject),
data = inhaler, family = "cumulative")
make_stancode(count ~ zAge + zBase * Trt + (1|patient),
data = epilepsy, family = "poisson")
# }
```

*Documentation reproduced from package brms, version 2.14.4, License: GPL-2*