Fit Bayesian generalized (non-)linear multivariate multilevel models
using 'Stan' for full Bayesian inference. A wide range of distributions
and link functions are supported, allowing users to fit -- among others --
linear, robust linear, count data, survival, response times, ordinal,
zero-inflated, hurdle, and even self-defined mixture models all in a
multilevel context. Further modeling options include non-linear and
smooth terms, auto-correlation structures, censored data, meta-analytic
standard errors, and quite a few more. In addition, all parameters of the
response distribution can be predicted in order to perform distributional
regression. Prior specifications are flexible and explicitly encourage
users to apply prior distributions that actually reflect their beliefs.
Model fit can easily be assessed and compared with posterior predictive
checks and leave-one-out cross-validation. References: Bürkner (2017)
The brms package provides an interface to fit Bayesian generalized (non-)linear multivariate multilevel models using Stan, which is a C++ package for performing full Bayesian inference (see http://mc-stan.org/). The formula syntax is very similar to that of the package lme4 to provide a familiar and simple interface for performing regression analyses. A wide range of distributions and link functions are supported, allowing users to fit -- among others -- linear, robust linear, count data, survival, response times, ordinal, zero-inflated, hurdle, and even self-defined mixture models all in a multilevel context. Further modeling options include non-linear and smooth terms, auto-correlation structures, censored data, missing value imputation, and quite a few more. In addition, all parameters of the response distribution can be predicted in order to perform distributional regression. Multivariate models (i.e. models with multiple response variables) can be fitted, as well. Prior specifications are flexible and explicitly encourage users to apply prior distributions that actually reflect their beliefs. Model fit can easily be assessed and compared with posterior predictive checks, leave-one-out cross-validation, and Bayes factors.
library(brms)
As a simple example, we use poisson regression to model the seizure counts in epileptic patients to investigate whether the treatment (represented by variable Trt
) can reduce the seizure counts and whether the effect of the treatment varies with the baseline number of seizures a person had before treatment (variable log_Base4_c
). As we have multiple observations per person, a group-level intercept is incorporated to account for the resulting dependency in the data.
fit1 <- brm(count ~ log_Age_c + log_Base4_c * Trt + (1|patient),data = epilepsy, family = poisson())
The results (i.e. posterior samples) can be investigated using
summary(fit1)#> Links: mu = log#> Formula: count ~ log_Age_c + log_Base4_c * Trt + (1 | patient)#> Data: epilepsy (Number of observations: 236)#> Samples: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;#> total post-warmup samples = 4000#>#> Group-Level Effects:#> ~patient (Number of levels: 59)#> Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat#> sd(Intercept) 0.55 0.07 0.43 0.70 966 1.01#>#> Population-Level Effects:#> Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat#> Intercept 1.79 0.11 1.56 2.02 1093 1.00#> log_Age_c 0.47 0.37 -0.26 1.22 1350 1.00#> log_Base4_c 0.88 0.14 0.61 1.16 1142 1.00#> Trt1 -0.33 0.16 -0.64 -0.03 1094 1.00#> log_Base4_c:Trt1 0.34 0.22 -0.08 0.76 1192 1.00#>#> Samples were drawn using sampling(NUTS). For each parameter, Eff.Sample#> is a crude measure of effective sample size, and Rhat is the potential#> scale reduction factor on split chains (at convergence, Rhat = 1).
On the top of the output, some general information on the model is given, such as family, formula, number of iterations and chains. Next, group-level effects are displayed seperately for each grouping factor in terms of standard deviations and (in case of more than one group-level effect per grouping factor; not displayed here) correlations between group-level effects. On the bottom of the output, population-level effects (i.e. regression coefficients) are displayed. If incorporated, autocorrelation effects and family specific parameters (e.g. the residual standard deviation 'sigma' in normal models) are also given.
In general, every parameter is summarized using the mean ('Estimate') and the standard deviation ('Est.Error') of the posterior distribution as well as two-sided 95% credible intervals ('l-95% CI' and 'u-95% CI') based on quantiles. We see that the coefficient of Trt
is negative with a completely negative 95%-CI indicating that, on average, the treatment reduces seizure counts by some amount. Further, we find little evidence that the treatment effect varies with the baseline number of seizures.
The last two values ('Eff.Sample' and 'Rhat') provide information on how well the algorithm could estimate the posterior distribution of this parameter. If 'Rhat' is considerably greater than 1, the algorithm has not yet converged and it is necessary to run more iterations and / or set stronger priors.
To visually investigate the chains as well as the posterior distributions, we can use the plot
method. If we just want to see results of the regression coefficients of Trt
and log_Base4_c
, we go for
plot(fit1, pars = c("Trt", "log_Base4_c"))
A more detailed investigation can be performed by running launch_shinystan(fit1)
. To better understand the relationship of the predictors with the response, I recommend the marginal_effects
method:
plot(marginal_effects(fit1, effects = "log_Base4_c:Trt"))
This method uses some prediction functionality behind the scenes, which can also be called directly. Suppose that we want to predict responses (i.e. seizure counts) of a person in the treatment group (Trt = 1
) and in the control group (Trt = 0
) with average age and average number of previous seizures. Than we can use
newdata <- data.frame(Trt = c(0, 1), log_Age_c = 0, log_Base4_c = 0)predict(fit1, newdata = newdata, re_formula = NA)#> Estimate Est.Error 2.5%ile 97.5%ile#> [1,] 6.00375 2.517999 2 11#> [2,] 4.33475 2.087530 1 9
We need to set re_formula = NA
in order not to condition of the group-level effects. While the predict
method returns predictions of the responses, the fitted
method returns predictions of the regression line.
fitted(fit1, newdata = newdata, re_formula = NA)#> Estimate Est.Error 2.5%ile 97.5%ile#> [1,] 5.999611 0.6901598 4.773145 7.517943#> [2,] 4.320005 0.4810514 3.385490 5.290729
Both methods return the same etimate (up to random error), while the latter has smaller variance, because the uncertainty in the regression line is smaller than the uncertainty in each response. If we want to predict values of the original data, we can just leave the newdata
argument empty.
Suppose, we want to investigate whether there is overdispersion in the model, that is residual variation not accounted for by the response distribution. For this purpose, we include a second group-level intercept that captures possible overdispersion.
fit2 <- brm(count ~ log_Age_c + log_Base4_c * Trt + (1|patient) + (1|obs),data = epilepsy, family = poisson())
We can then go ahead and compare both models via approximate leave-one-out cross-validation.
loo(fit1, fit2)#> LOOIC SE#> fit1 1347.06 74.22#> fit2 1198.44 28.61#> fit1 - fit2 148.62 54.52
Since smaller LOOIC
values indicate better fit, we see that the model accounting for overdispersion fits substantially better. The post-processing methods we have shown so far are just the tip of the iceberg. For a full list of methods to apply on fitted model objects, type methods(class = "brmsfit")
.
To install the latest release version from CRAN use
install.packages("brms")
The current developmental version can be downloaded from github via
if (!requireNamespace("devtools")) {install.packages("devtools")}devtools::install_github("paul-buerkner/brms")
Because brms is based on Stan, a C++ compiler is required. The program Rtools (available on https://cran.r-project.org/bin/windows/Rtools/) comes with a C++ compiler for Windows. On Mac, you should install Xcode. For further instructions on how to get the compilers running, see the prerequisites section on https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started.
Detailed instructions and case studies are given in the package's extensive vignettes. See vignette(package = "brms")
for an overview. For documentation on formula syntax, families, and prior distributions see help("brm")
.
Please cite one or more of the following publications:
Questions can be asked on the Stan forums on Discourse. To propose a new feature or report a bug, please open an issue on GitHub.
If you have already fitted a model, just apply the stancode
method on the fitted model object. If you just want to generate the Stan code without any model fitting, use the make_stancode
function.
When you fit your model for the first time with brms, there is currently no way to avoid compilation. However, if you have already fitted your model and want to run it again, for instance with more samples, you can do this without recompilation by using the update
method. For more details see help("update.brmsfit")
.
The rstanarm package is similar to brms in that it also allows to fit regression models using Stan for the backend estimation. Contrary to brms, rstanarm comes with precompiled code to save the compilation time (and the need for a C++ compiler) when fitting a model. However, as brms generates its Stan code on the fly, it offers much more flexibility in model specification than rstanarm. Also, multilevel models are currently fitted a bit more efficiently in brms. For detailed comparisons of brms with other common R packages implementing multilevel models, see vignette("brms_multilevel")
and vignette("brms_overview")
.
gp
. (#540)brm_multiple
via the future package. (#364)kfold_predict
. (#468)oos
of extract_draws
. (#539)marginal_effects
more robust to
the usage of non-standard variable names.fitted(..., scale = "linear")
with ordinal models
thanks to Andrew Milne. (#557)marginal_smooths
with ordinal models
thanks to Andrew Milne. (#570)me
terms thanks to the GitHub user hlluik. (#571)warmup
samples when using
update.brmsfit
.rstan::stan_model
via argument
stan_model_args
in brm
. (#525)file
in add_ic
after adding model fit criteria. (#478)density_ratio
.offset
.update_adterms
.marginal_smooths
.marginal_effects
to better display ordinal and
categorical models via argument categorical
. (#491, #497)kfold
to offer more options for specifying
omitted subsets. (#510)nlpar
in method fitted
.cmc
of brmsformula
and related
functions thanks to Marie Beisemann.bridge_sampler
method even if
prior samples are drawn within the model. (#485)custom_family
.fixef
, ranef
,
and coef
via argument pars
. (#520)overwrite
already stored fit indices
when using add_ic
.resp
when post-processing
univariate models thanks to Ruben Arslan. (#488)ordinal
of marginal_effects
. (#491)exact_loo
of kfold
. (#510)binomial
families without specifying trials
.update
on
brmsfit objects thanks to Emmanuel Charpentier. (#490)Post.Prob = 1
if Evid.Ratio = Inf
in
method hypothesis
thanks to Andrew Milne. (#509)file
in brm_multiple
.stanvar
. (#459)gp
. This may lead to a
considerable increase in sampling efficiency. (#300)loo_R2
.loop
in brmsformula
.horseshoe
and lasso
priors to be set on special
population-level effects.set_prior
.brm
via argument file
. (#472)hypothesis
.stan_funs
in brm
in favor of using the
stanvars
argument for the specification of custom Stan functions.flist
and ...
in nlf
.dpar
in lf
and nlf
.lognormal
models (#460).cumulative
, sratio
, and cratio
. (#433)kfold
. (#441)launch_shinystan
due to which the
maximum treedepth was not correctly displayed thanks to
Paul Galpern. (#431)cor_car
to support intrinsic CAR models in pairwise
difference formulation thanks to the case study of Mitzi Morris.loo
and related methods for non-factorizable normal models.posterior_summary
. This affects the
output of predict
and related methods if summary = TRUE
. (#425)pointwise
dynamically in loo
and related methods. (#416)cor_car
in multivariate models with residual correlations
thanks to Quentin Read. (#427)beta
models
thanks to Hans van Calster. (#404)launch_shinystan.brmsfit
so that all parameters
are now shown correctly in the diagnose tab. (#340)custom_family
. (#381)mi
addition term. (#27, #343)mi
terms on the right-hand side of
model formulas. (#27)mo
, me
, and mi
.
(#313)model_weights
and loo_model_weights
providing several
options to compute model weights. (#268)posterior_average
to extract posterior samples averaged
across models. (#386)by
in function gr
. (#365)stanvar
. (#219, #357)mmc
terms. (#353)shifted_lognormal
. (#218)make_conditions
to ease preparation of conditions for
marginal_effects
.weibull
and exgaussian
models to be
consistent with other model classes. Post-processing of related models fitted
with earlier version of brms
is no longer possible.ordinal
models as directly indicating categories
even if the lowest integer is not one.hypothesis
method thanks to the ideas of Matti Vuorre.
(#362)by
variables as facets in marginal_smooths
.cor_bsts
correlation structure.:
operator to combine groups in multi-membership terms thanks to
Gang Chen.LOO
with argument reloo = TRUE
thanks to Peter Konings. (#348)predict
when applied to categorical models thanks to Lydia
Andreyevna Krasilnikova and Thomas Vladeck. (#336, #345)weibull
and frechet
models
thanks to the GitHub user philj1s. (#375)binomial
models thanks to the GitHub
user SeanH94. (#382)model.frame
thanks to Daniel
Luedecke. (#393)brm_multiple
thanks
to Ruben Arslan. (#27)brmsfit
objects
via function combine_models
.pp_average
. (#319)ordinal
to
marginal_effects
to generate special
plots for ordinal models thanks to the idea
of the GitHub user silberzwiebel. (#190)scope
in method hypothesis
. (#327)Stan
functions
exported via export_functions
using
argument vectorize
.me
terms thanks to Ruben Arslan.
As a side effect, it is no longer possible to define
priors on noise-free Xme
variables directly, but
only on their hyper-parameters meanme
and sdme
.cor_bsts
structure thanks to Joshua Edward Morten. (#312)posterior_summary
and posterior_table
both being used to
summarize posterior samples and predictions.acat
and cratio
models
thanks to Peter Phalen. (#302)pointwise
computation of LOO
and WAIC
in multivariate models with estimated
residual correlation structure.newdata
.This is the second major release of brms
. The main
new feature are generalized multivariate models, which now
support everything already possible in univariate models,
but with multiple response variables. Further, the internal
structure of the package has been improved considerably to be
easier to maintain and extend in the future.
In addition, most deprecated functionality and arguments have
been removed to provide a clean new start for the package.
Models fitted with brms
1.0 or higher should remain
fully compatible with brms
2.0.
gaussian
and student
models. All features
supported in univariate models are now also available in
multivariate models. (#3)categorical
models.Intercept
to improve convergence
of more complex distributional models.summary
output. (#280)re.form
as an alias of
re_formula
to the methods posterior_predict
,
posterior_linpred
, and predictive_error
for consistency with other packages making use of
these methods. (#283)summary
output. (#277)predict
and related methods thanks to Fanyi Zhang. (#224)disp
from the package.fixef
,
ranef
, coef
, and VarCorr
.brms
< 1.0,
which used the multivariate 'trait'
syntax
orginally deprecated in brms
1.0.summary
method cleaner and less error prone.brm
to avoid unexpected behavior in simulation studies.stan_funs
in brmsfit
objects
to allow using update
on models with user-defined
Stan functions thanks to Tom Wallis. (#288)intercept
in group-level terms thanks to
the GitHub user ASKurz. (#279)predict
and related
methods when setting sample_new_levels = "gaussian"
in models with only one group-level effect.
Thanks to Timothy Mastny. (#286)me
.Ksub
, exact_loo
and group
to method kfold
for
defining omitted subsets according to a
grouping variable or factor.se
in skew_normal
models.identity
links on
all parameters of the wiener
family
thanks to Henrik Singmann. (#276)fitted
when returning linear predictors
of ordinal models thanks to the GitHub user atrolle. (#274)marginal_smooths
occuring for multi-membership models thanks to
Hans Tierens.posterior_linpred
and posterior_interval
for consistency
with other model fitting packages based on
Stan
.theme_black
providing a black ggplot2
theme.prob
to
summary
, which allows to control the
width of the computed uncertainty intervals. (#259)newdata
to the
kfold
method.plot
method of marginal_effects
to improve
control over the appearences of the plots.cor_bsts
structure more informative.autocor
argument
within brmsformula
objects.hypothesis
.ggplot2
when attaching brms
. (#256)summary.brmsfit
. (#263)extract_draws
and linear_predictor
to be more consistent
with the rest of the package.Stan
parser
when calling brm
to get informative
error messages about invalid priors.set_prior
.data.frame
objects
correctly in hypothesis.default
.marginal_effects
.bridge_sampler
, bayes_factor
,
and post_prob
all powered by the
bridgesampling
package.bayes_R2
method.+
operator and the helper functions
lf
, nlf
, and set_nl
.+
operator.nlpar
argument of
set_prior
into the three arguments
resp
, dpar
, and nlpar
to allow for more flexible prior specifications.bridge_sampler
to be
working correctly.stanfit
object.auxpar
of
fitted.brmsfit
to dpar
.launch_shinystan
generic
provided by the shinystan
package.bayesplot::theme_default()
as the default ggplot2
theme when
attaching brms
.brms
overview paper as published in the
Journal of Statistical Software.fitted
with hurdle_lognormal
models thanks to
Meghna Krishnadas.sigma
in asym_laplace
models thanks to
Anna Josefine Sorensen.cor_car
thanks to the case
study of Max Joseph.cor_sar
. Currently works
for families gaussian
and student
.skew_normal
. Thanks to Stephen Martin
for suggestions on the parameterization.reloo
to perform exact
cross-validation for problematic observations
and kfold
to perform k-fold cross-validation
thanks to the Stan Team.horseshoe
prior thanks to Juho Piironen
and Aki Vehtari.new_objects
to various
post-processing methods to allow for passing of
data objects, which cannot be passed via
newdata
.future
package.threshold
in brm
and instead recommend passing threshold
directly
to the ordinal family functions.autocor
slot in brmsfit
objects to an empty
cor_brms
object.Stan
code by combining
declarations and definitions where possible.pp_check
when the variable specified in argument
x
has attributes thanks to
Paul Galpern.summary.brmsfit
for models with only a single observation.gp
specified in the model formula (#221).fixef
, ranef
,
coef
, and VarCorr
to be more flexible
and consistent with other post-processing methods (#200).hypothesis
to be
applicable on all objects coercible to a
data.frame
(#198).spaghetti
in
marginal_effects
and marginal_smooths
.add_ic
to
store and reuse information criteria in
fitted model objects (#220).as.array
method
for brmsfit
objects.exgaussian
models thanks to
Alex Forrence (#222).transform
in marginal_effects
thanks to Markus Gesmann.marginal_effects
occuring for some models with autocorrelation terms
thanks to Markus Gesmann.cor_bsts
structure thanks to Andrew Ellis.zero_one_inflated_beta
.bayesplot
version 1.2.0.disp
.mixture
.pp_mixture
to compute
posterior probabilities of mixture component
memberships thanks to a discussion with Stephen Martin.predict
and related
methods through argument sample_new_levels
.
Thanks to Tom Wallis and Jonah Gabry for a detailed
discussion about this feature.loo_predict
, loo_linpred
,
and loo_predictive_interval
for computing
LOO predictions thanks to Aki Vehtari and Jonah Gabry.offset
in formulas
of non-linear and auxiliary parameters.identity
link for
all auxiliary parameters.negative_rt
in
predict
and posterior_predict
to
distinquish responses on the upper and lower
boundary in wiener
diffusion models
thanks to Guido Biele.control_params
to
conveniently extract control parameters of the
NUTS sampler.int_conditions
in
marginal_effects
for enhanced plotting of
two-way interactions thanks to a discussion with
Thomas Kluth.conditions
argument of marginal_effects
.stanplot
to correctly
handle some new mcmc_
plots of the
bayesplot
package.update
method to
only recompile models when the Stan
code
changes.summary
or print
on brmsfit
objects.conditions
when calling marginal_effects
.pp_check
when specifying
argument newdata
together with arguments
x
or group
.hypothesis
to "star"
in order to avoid
problems with zero length column names thanks to
the GitHub user puterleat.summary
output thanks to Thomas Kluth.horseshoe
and lasso
priors to be applied on population-level effects
of non-linear and auxiliary parameters.Stan
models
in update.brmsfit
via argument
recompile
.Beta
models thanks to Vivian Lam.brms
thanks
to Vivian Lam.group
in
method pp_check
thanks to Thomas K.subset
and nsamples
working correctly in marginal_smooths
.gen_extreme_value
.horseshoe
prior thanks to Juho Piironen.mu
as an alternative to specifying effects within
the formula
argument in function
brmsformula
.auxpar
of method fitted
."brms_multilevel"
, in which
the advanced formula syntax of brms
is explained
in detail using several examples.rstan
in
element version
of brmsfit
objects.von_mises
models thanks to John Kirwan.asym_laplace
(asymmetric Laplace distribution).brmsformula
.brmsformula
.family
to be specified in
brmsformula
.frechet
for modelling
strictly positive responses.prior_
allowing
to specify priors using one-sided formulas or quote
.Stan
directly without
performing any checks by setting check = FALSE
in set_prior
.nsamples
to extract
the number of posterior samples.parse_bf
.marginal_effects
or marginal_smooths
.brmsformula
objects to be more reliable and easier to extend.nu
never
falls below 1
to reduce convergence problems
when using family student
.nonlinear
.geometric
.cov_fixed
to cor_fixed
.fitted
method to be easier to extend in the future.nlme
instead
of lme4
to remove dependency on the latter one.structure
to NULL
anymore to get rid of warnings in \R-devel.by
variables thanks to
Milani Chaloupka.Stan
code thanks
to the GitHub user bschneider.Stan
code.algorithm
correctly in update.brmsfit
.marginal_effects
when using family
wiener
thanks to Andrew Ellis.fitted
when applied
to zero_inflated_beta
models thanks to
Milani Chaloupka.brms
< 1.0.0.disc
('discrimination') to be used in ordinal models.
By default it is not estimated but fixed to one.marginal_effects
plots of
two-way interactions of variables that were
not explicitely modeled as interacting.rstan
to 'Imports' and Rcpp
to 'Depends' in order to avoid loading rstan
into the global environment automatically.me
in the model formulae.mm
in grouping terms.exgaussian
(exponentially modified Gaussian distribution)
and wiener
(Wiener diffusion model distribution)
specifically suited to handle for response times.lasso
prior as an alternative
to the horseshoe
prior for sparse models.log_posterior
,
nuts_params
, rhat
, and neff_ratio
for brmsfit
objects to conveniently access
quantities used to diagnose sampling behavior.as.mcmc
using
argument combine_chains
.sigma
in models with known standard errors of
the response by setting argument sigma
to
TRUE
in addition function se
.marginal_smooths
method.data
to be explicitely
specified in all user facing functions.stanplot
method
to use bayesplot
on the backend.bayesplot
theme as the default
in all plotting functions.mo
and cs
to specify monotonic and category specific effects
respectively.marginal_effects
to avoid potential
naming conflicts.cluster
and use
the native cores
argument of rstan
instead.cluster_type
as it is
no longer required to apply forking.partial
argument.hurdle_lognormal
specifically suited for zero-inflated continuous responses.pp_check
method to perform
various posterior predictive checks
using the bayesplot
package.marginal_smooths
method to
better visualize smooth terms.horseshoe
prior.prior
and prior_string
as aliases of set_prior
, the former
allowing to pass arguments without quotes ""
using non-standard evaluation.coef
method to better
handle category specific group-level effects.prior_summary
method
for brmsfit
objects to obtain a summary
of prior distributions applied.sample_prior = TRUE
even in models
with an internal temporary intercept used to improve
sampling efficiency.posterior_predict
,
predictive_error
and log_lik
as
(partial) aliases of predict
, residuals
,
and logLik
respectively.hypothesis
method to be less
influenced by MCMC error.bayesplot
package as the
new backend of plot.brmsfit
.mgcv
when parsing smooth terms
to make sure all arguments are correctly handled.marginal_effects
to consistently
produce plots for all covariates in non-linear models
thanks to David Auty.update
method to better recognize
situations where recompliation of the Stan
code
is necessary thanks to Raphael P.H.update
the sample_prior
argument to value "only"
.t2
smooth terms based on
multiple covariates.cens
in the model formula.residuals
also based
on predicted values instead of fitted values.bcs
in parameter names
of category specific effects and the prefix bm
in parameter names of monotonic effects (instead
of the prefix b
) to simplify their identifaction.ggplot2
version 2.2.cumulative
and
sratio
models thanks to Peter Congdon.gamma
models from being compiled
thanks to Tim Beechey.predict
and related methods when two-level factors or
logical variables were used as covariates in
non-linear models thanks to Martin Schmettow.prior_samples
method for models with
multiple group-level terms that refer to the same
grouping factor thanks to Marco Tullio Liuzza.marginal_effects
for weighted models.\subsection{MINOR CHANGES
make_standata
.This is one of the largest updates of brms
since its
initial release. In addition to many new features,
the multivariate 'trait'
syntax has been removed
from the package as it was confusing for users, required
much special case coding, and was hard to maintain.
See help(brmsformula)
for details of the formula
syntax applied in brms
.
lme4
syntax.zi
and
hu
defining zero-inflation / hurdle probabilities.von_mises
family to model
circular responses.brmsfamily
function for
convenient specification of family
objects.t2
smoothing
terms for new data.trunc
in order to model varying
truncation points.cauchy
family
after several months of deprecation.predict
method now returns predicted
probabilities instead of absolute frequencies of
samples for ordinal and categorical models.marginal_effects
plots if sensible.robust
argument to TRUE
in
marginal_effects.brmsfit
.logLik.brmsfit
thanks to Tom Wallis.ranef
and coef
methods with non-linear
models.dplyr
datasets thanks
to the GitHub user Atan1988.s
and t2
functions in the model formula.as.data.frame
and as.matrix
methods for brmsfit
objects.gaussian("log")
family no longer implies a log-normal distribution, but
a normal distribution with log-link to match the behavior of glm
. The
log-normal distribution can now be specified via family lognormal
.Stan
models to match the recommended syntax of Stan
2.10.ngrps
method should now always return the correct result for non-linear
models.marginal_effects
for models using the reserved variable
intercept
thanks to Frederik Aust.print
method of brmshypothesis
objects that could lead to
duplicated and thus invalid row names.summary
method.brms
while having
rstan
>= 2.10.0 installed thanks to the GitHub user cwerner87.formula
argument to
indicate nested grouping structures.WAIC
and LOO
based on the pointwise log-likelihood using
argument pointwise
to substantially reduce memory requirements.marginal_effects
plots for factors.formula
using the update
method.marginal_effects
for
predictors that were generated with the base::scale
function thanks to Tom
Wallis.marginal_effects
to be passed to the effects
argument in any order.predict
and related
methods when called with newdata
in models using the poly
function thanks to
Brock Ferguson.monotonic
effects allowing to use ordinal predictors without
assuming their categories to be equidistant.disp
to define multiplicative factors on
dispersion parameters. For linear models, disp
applies to the residual
standard deviation sigma
so that it can be used to weight observations.sparse
argument
of brm
. This can considerably reduce working memory requirements if the
predictors contain many zeros.cor_fixed
correlation structure to allow for fixed user-defined
covariance matrices of the response variable.Stan
functions via argument stan_funs
of brm
.expose_functions
method allowing to expose self-defined Stan
functions in R
.update
method to allow all model parts to be
updated.Stan
code and data generating functions to be more consistent and
easier to extent.marginal_effects
method are
always smooth.formula
argument.Stan
code when using very long non-linear
model formulas thanks to Emmanuel Charpentier.R
, occuring for ordinal
models with multiple category specific effects. This could lead to incorrect
outputs of predict
, fitted
, and logLik
for these models."contrasts"
option is not used when
post-processing a model.nonlinear
argument in brm
.marginal_effects
method thanks
to the help of Ruben Arslan.zero_inflated_beta
thanks
to the idea of Ali Roshan Ghias.lb
and ub
in function set_prior
thanks to the idea of Joel
Gombin.as.mcmc
method for compatibility with the coda
package.WAIC
, LOO
, and logLik
methods with new data.brms
is fully compatible with loo
version 0.1.5.summary
by default anymore to reduce computation
time of the method for larger models.cauchy
family is now deprecated and will be removed soon as it often has
convergence issues and not much practical application anyway.rstan
(i.e., chains = 4
and warmup = iter / 2
).theme
argument in all plotting functions.plot
method.Stan
functions to inst/chunks
and incorporate
them into the models using rstan::stanc_builder
. Also, add unit tests for
these functions.newdata
for zero-inflated and hurdle
models thanks to Ruben Arslan.newdata
if it is a subset of the data
stored in a brmsfit
object thanks to Ruben Arslan.NA
thanks
to Raphael Royaute.predict
method occurring for some multivariate models so
that it now always returns the predictions of all response variables, not just
the first one.hurdle_poisson
and
hurdle_negbinomial
models. This may lead to minor changes in the values
obtained by WAIC
and LOO
for these models.algorithm
in the brm
function.Beta
.zero_inflated_binomial
.bernoulli
to fit (among others)
2PL IRT models.formula
argument for zero-inflated and hurdle models so that
predictors can be included in only one of the two model parts thanks to the idea
of Wade Blanchard.coef
method.residuals
method with newdata
thanks to the idea of Friederike
Holz-Ebeling.predict
,
fitted
, and residuals
methods using argument allow_new_levels
.predict
, fitted
, and residuals
methods using argument re_formula
.plot
method for objects returned by method hypothesis
to visualize
prior and posterior distributions of the hypotheses being tested.formula
argument to reliably
allow terms with more than one variable (e.g., y/x ~ 1
).(random || group)
terms in formula
thanks to Ali
Roshan Ghias.Stan
code of ordinal models to improve
readability as well as sampling efficiency.LOO
or WAIC
are only performed when
models are based on the same responses.lme4
package to avoid unnecessary function
masking. This leads to a change in the argument order of method VarCorr
.ggplot
theme in the plot
method through argument theme
.n.
prefix in arguments n.iter
, n.warmup
, n.thin
,
n.chains
, and n.cluster
of the brm
function. The old argument names remain
usable as deprecated aliases.hypothesis
method that could cause valid model parameters
to be falsely reported as invalid.prior_samples
method that could cause prior samples of
parameters of the same class to be artifically correlated.Stan
code of linear models with moving-average effects and non-identity
link functions so that they no longer contain code related solely to
autoregressive effects.formula
that could cause complicated random
effects terms to be falsely treated as fixed effects.fitted
and predict
methods with
newdata
thanks to Ali Roshan Ghias.inverse.gaussian
.cor_ar
and cor_arma
functions.cauchit
link function.family
argument.rstan
plotting functions using the stanplot
method.loo
package when comparing multiple
fitted models.Stan
code to slightly improve sampling efficiency.cor_ar
to the
cor_arr
function as the result of implementing AR effects of residuals.newdata
used in the fitted
and predict
method.standata
is now the only way to extract data that was passed to
Stan
from a brmsfit
object.Stan
code for models containing no random effects.student
family to
gamma(2,0.1)
.VarCorr
.make_stancode
function to give users direct access to Stan
code
generated by brms
.brmdata
function to make_standata
. The former remains usable as
a deprecated alias.predict
method was
called with newdata
.rstan
compilation routines that could occasionally
cause R to crash.brms
work correctly with loo
version 0.1.3 thanks to Mauricio Garnier
Villarreal and Jonah Gabry.gaussian
models with log
link.loo
package.shinystan
with S3 method launch_shiny
.get_prior
and set_prior
to make prior specifications easier.predict
.fitted
and residuals
to compute fitted values and
residuals, respectively.WAIC
and predict
are removed from the brm
function, as they
are no longer necessary.cluster_type
in function brm
allowing to choose the cluster
type created by the parallel package.VarCorr
now always returns covariance matrices regardless of
whether correlations were estimated.hypothesis
related to the calculation of
Bayes-factors for point hypotheses.hypothesis
.||
-syntax for random effects allowing for the estimation of
random effects standard deviations without the estimation of correlations.:
.hypothesis
to be used with all parameter classes not
just fixed effects. In addition, one-sided hypothesis testing is now possible.multigaussian
allowing for multivariate normal
regression.bernoulli
for dichotomous response variables as a more
efficient alternative to families binomial
or categorical
in this special
case.rstan
is
finally on CRAN.Stan
.__
to avoid naming
conflicts.poly(x,3)
) in the formula
argument of function brm
.ranef
around
zero.JAGS
code from the package.hypothesis
leading to an error when numbers with
decimal places were used in the formulation of the hypotheses.ranef
that caused an error for grouping factors with
only one random effect.parnames
and posterior_samples
for class 'brmsfit'
to extract parameter names and posterior samples for given parameters,
respectively.hypothesis
for class brmsfit
allowing to test
non-linear hypotheses concerning fixed effects.addition
in function brm to get a more flexible
approach in specifying additional information on the response variable (e.g.,
standard errors for meta-analysis). Alternatively, this information can also be
passed to the formula
argument directly.addition
of
function brm.cov.ranef
in the brm
function allowing for
customized covariance structures of random effects thanks to the idea of Boby
Mathew.autocor
in function brm allowing for autocorrelation
of the response variable.cor.ar
, cor.ma
, and cor.arma
, to be used with
argument autocor
for modeling autoregressive, moving-average, and
autoregressive-moving-average models.predict = TRUE
.silent = TRUE
.brmsfit
to be returned by the brm
function.brmsfit
: summary
, print
, plot
, predict
,
fixef
, ranef
, VarCorr
, nobs
, ngrps
, and formula
.silent
in the brm
function, allowing to suppress
most of Stan
's intermediate output.negbinomial
(negative binomial) and geometric
to
allow for more flexibility in modeling count data.cumulative
.