rstanarm (version 2.13.1)

stan_glmer: Bayesian generalized linear models with group-specific terms via Stan

Description

Bayesian inference for GLMs with group-specific coefficients that have unknown covariance matrices with flexible priors.

Usage

stan_glmer(formula, data = NULL, family = gaussian, subset, weights, na.action = getOption("na.action", "na.omit"), offset, contrasts = NULL, ..., prior = normal(), prior_intercept = normal(), prior_ops = prior_options(), prior_covariance = decov(), prior_PD = FALSE, algorithm = c("sampling", "meanfield", "fullrank"), adapt_delta = NULL, QR = FALSE, sparse = FALSE)
stan_lmer(formula, data = NULL, subset, weights, na.action = getOption("na.action", "na.omit"), offset, contrasts = NULL, ..., prior = normal(), prior_intercept = normal(), prior_ops = prior_options(), prior_covariance = decov(), prior_PD = FALSE, algorithm = c("sampling", "meanfield", "fullrank"), adapt_delta = NULL, QR = FALSE)
stan_glmer.nb(formula, data = NULL, subset, weights, na.action = getOption("na.action", "na.omit"), offset, contrasts = NULL, link = "log", ..., prior = normal(), prior_intercept = normal(), prior_ops = prior_options(), prior_covariance = decov(), prior_PD = FALSE, algorithm = c("sampling", "meanfield", "fullrank"), adapt_delta = NULL, QR = FALSE)

Arguments

formula, data, family
Same as for glmer.
subset, weights, offset
Same as glm.
na.action, contrasts
Same as glm, but rarely specified.
...
For stan_glmer, further arguments passed to sampling (e.g. iter, chains, cores, etc.) or to vb (if algorithm is "meanfield" or "fullrank"). For stan_lmer and stan_glmer.nb, ... should also contain all relevant arguments to pass to stan_glmer (except family).
prior
The prior distribution for the regression coefficients. prior can be a call to normal, student_t, cauchy, hs or hs_plus. See priors for details. To omit a prior ---i.e., to use a flat (improper) uniform prior--- prior can be set to NULL, although this is rarely a good idea. (Note: unless QR=TRUE, if the scaled argument to prior_options is left at its default and recommended value of TRUE, then the scale(s) of prior may be modified internally based on the scales of the predictors, as in the arm package. See priors for details on the rescaling and prior_summary for a summary of the priors used for a particular model.)
prior_intercept
The prior distribution for the intercept. prior_intercept can be a call to normal, student_t or cauchy. See priors for details. To to omit a prior ---i.e., to use a flat (improper) uniform prior--- set prior_intercept to NULL. (Note: if a dense representation of the design matrix is utilized ---i.e., if the sparse argument is left at its default value of FALSE--- then the prior distribution for the intercept is set so it applies to the value when all predictors are centered.)
prior_ops
Additional options related to prior distributions. Can be NULL to omit a prior on the dispersion and see prior_options otherwise.
prior_covariance
Cannot be NULL; see decov for more information about the default arguments.
prior_PD
A logical scalar (defaulting to FALSE) indicating whether to draw from the prior predictive distribution instead of conditioning on the outcome.
algorithm
A string (possibly abbreviated) indicating the estimation approach to use. Can be "sampling" for MCMC (the default), "optimizing" for optimization, "meanfield" for variational inference with independent normal distributions, or "fullrank" for variational inference with a multivariate normal distribution. See rstanarm-package for more details on the estimation algorithms. NOTE: not all fitting functions support all four algorithms.
adapt_delta
Only relevant if algorithm="sampling". See adapt_delta for details.
QR
A logical scalar (defaulting to FALSE) but if TRUE applies a scaled qr decomposition to the design matrix, $X = Q* R*$, where $Q* = Q (n-1)^0.5$ and $R* = (n-1)^(-0.5) R$. The coefficients relative to $Q*$ are obtained and then premultiplied by the inverse of $R*$ to obtain coefficients relative to the original predictors, $X$. These transformations do not change the likelihood of the data but are recommended for computational reasons when there are multiple predictors. However, because the coefficients relative to $Q*$ are not very interpretable it is hard to specify an informative prior. Setting QR=TRUE is therefore only recommended if you do not have an informative prior for the regression coefficients.
sparse
A logical scalar (defaulting to FALSE) indicating whether to use a sparse representation of the design (X) matrix. Setting this to TRUE will likely be twice as slow, even if the design matrix has a considerable number of zeros, but it may allow the model to be estimated when the computer has too little RAM to utilize a dense design matrix. If TRUE, the the design matrix is not centered (since that would destroy the sparsity) and it is not possible to specify both QR = TRUE and sparse = TRUE.
link
For stan_glmer.nb only, the link function to use. See neg_binomial_2.

Value

A stanreg object is returned for stan_glmer, stan_lmer, stan_glmer.nb.

Details

The stan_glmer function is similar in syntax to glmer but rather than performing (restricted) maximum likelihood estimation of generalized linear models, Bayesian estimation is performed via MCMC. The Bayesian model adds independent priors on the regression coefficients (in the same way as stan_glm) and priors on the terms of a decomposition of the covariance matrices of the group-specific parameters. See priors for more information about the priors. The stan_lmer function is equivalent to stan_glmer with family = gaussian(link = "identity"). The stan_glmer.nb function, which takes the extra argument link, is a simple wrapper for stan_glmer with family = neg_binomial_2(link).

References

Gelman, A. and Hill, J. (2007). Data Analysis Using Regression and Multilevel/Hierarchical Models. Cambridge University Press, Cambridge, UK. (Ch. 11-15)

See Also

stanreg-methods and glmer.

The vignette for stan_glmer and the Hierarchical Partial Pooling vignette.

Examples

Run this code
# see help(example_model) for details on the model below
if (!exists("example_model")) example(example_model) 
print(example_model, digits = 1)

Run the code above in your browser using DataCamp Workspace