Learn R Programming

rstanarm (version 2.10.1)

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

Description

Bayesian inference for GAMMs with flexible priors.

Usage

stan_gamm4(formula, random = NULL, family = gaussian(), data = list(), weights = NULL, subset = NULL, na.action, knots = NULL, drop.unused.levels = TRUE, ..., 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)

Arguments

formula, random, family, data, knots, drop.unused.levels
Same as for gamm4.
subset, weights, na.action
Same as glm, but rarely specified.
...
Further arguments passed to sampling (e.g. iter, chains, cores, etc.) or to vb (if algorithm is "meanfield" or "fullrank").
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 to omit a prior ---i.e., to use a flat (improper) uniform prior--- set prior to NULL.
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
Character 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.

Value

A stanreg object is returned for stan_gamm4.

Details

The stan_gamm4 function is similar in syntax to gamm4, which accepts a syntax that is similar to (but not quite as extensive as) that for gamm and converts it internally into the syntax accepted by glmer. But rather than performing (restricted) maximum likelihood estimation, the stan_gamm4 function utilizes MCMC to perform Bayesian estimation. The Bayesian model adds independent priors on the common 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, including the smooths. Estimating these models via MCMC avoids the optimization issues that often crop up with GAMMs and provides better estimates for the uncertainty in the parameter estimates. See gamm4 for more information about the model specicification and priors for more information about the priors.

See Also

stanreg-methods and gamm4.

Examples

Run this code
# see example(gamm4, package = "gamm4") but prefix gamm4() calls with stan_

Run the code above in your browser using DataLab