The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.
This package has functions to calculate marginal effects from
brms
models ( http://paul-buerkner.github.io/brms/ ). A
central motivator is to calculate average marginal effects (AMEs) for
continuous and discrete predictors in fixed effects only and mixed
effects regression models including location scale models.
This table shows an overview of currently supported models / features where “X” indicates a specific model / feature is currently supported. The column ‘Fixed’ means fixed effects only models. The column ‘Mixed’ means mixed effects models.
Distribution / Feature | Fixed | Mixed |
---|---|---|
Gaussian / Normal | :heavy_check_mark: | :heavy_check_mark: |
Bernoulli (logistic) | :heavy_check_mark: | :heavy_check_mark: |
Poisson | :heavy_check_mark: | :heavy_check_mark: |
Negative Binomial | :heavy_check_mark: | :heavy_check_mark: |
Gamma | :heavy_check_mark: | :heavy_check_mark: |
Beta | :heavy_check_mark: | :heavy_check_mark: |
Multinomial logistic | :x: | :x: |
Multivariate models | :x: | :x: |
Gaussian location scale models | :heavy_check_mark: | :heavy_check_mark: |
Natural log / square root transformed outcomes | :heavy_check_mark: | :heavy_check_mark: |
Monotonic predictors | :heavy_check_mark: | :heavy_check_mark: |
Custom outcome transformations | :x: | :x: |
In general, any distribution supported by brms
that
generates one and only one predicted value (e.g., not multinomial
logistic regression models) should be supported for fixed effects only
models. Also note that currently, only Gaussian random effects are
supported. This is not too limiting as even for Bernoulli, Poisson, etc.
outcomes, the random effects are commonly assumed to have a Gaussian
distribution.
Here is a quick syntax overview of how to use the main function,
brmsmargins()
.
<- .001
h <- brmsmargins(
ames object = model,
add = data.frame(x = c(0, h)),
contrasts = cbind("AME x" = c(-1 / h, 1 / h)),
effects = "fixedonly")
$ContrastSummary ames
<- brmsmargins(
ames object = model,
add = data.frame(x = c(0, 1)),
contrasts = cbind("AME x" = c(-1, 1)),
effects = "fixedonly")
$Summary
ames$ContrastSummary ames
<- .001
h <- brmsmargins(
ames object = model,
add = data.frame(x = c(0, h)),
contrasts = cbind("AME x" = c(-1 / h, 1 / h)),
effects = "integrateoutRE")
$ContrastSummary ames
<- brmsmargins(
ames object = model,
add = data.frame(x = c(0, 1)),
contrasts = cbind("AME x" = c(-1, 1)),
effects = "integrateoutRE")
$Summary
ames$ContrastSummary ames
<- .001
h <- brmsmargins(
ames object = model,
add = data.frame(x = c(0, h)),
contrasts = cbind("AME x" = c(-1 / h, 1 / h)),
dpar = "sigma",
effects = "integrateoutRE")
$ContrastSummary ames
<- brmsmargins(
ames object = model,
at = data.frame(x = c(0, 1)),
contrasts = cbind("AME x" = c(-1, 1)),
dpar = "sigma",
effects = "integrateoutRE")
$Summary
ames$ContrastSummary ames
Note that even on mixed effects models, it is possible to generate
predictions and marginal effects from the fixed effects only, just by
specifying effects = "fixedonly"
but this is probably not a
good idea generally so not shown by default.
Also note that for all of these examples ames$Summary
would have a summary of the averaged predicted values. These often are
useful for discrete predictors. For continuous predictors, if the focus
is on marginal effects, they often are not interesting. However, the
at
argument can be used with continuous predictors to
generate interesting averaged predicted values. For example, this would
get predicted values integrating out random effects for a range of ages
averaging (marginalizing) all other predictors / covariates.
<- brmsmargins(
ames object = model,
at = data.frame(age = c(20, 30, 40, 50, 60)),
effects = "integrateoutRE")
$Summary ames
You can install the package from CRAN by running this code:
install.packages("brmsmargins")
Alternately, for the latest, development version, run:
::install_github("JWiley/brmsmargins") remotes
There are three vignettes that introduce how to use the package for several scenarios.
dpar
in brms
. This
vignette shows how to calculate marginal effects from location scale
models for the scale part.These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.