cmdstan_glm | R Documentation |
Generalized linear modeling for Gaussian and gamma responses, with optional prior distributions for the coefficients, intercept, and auxiliary parameters.
cmdstan_glm(
formula,
family = gaussian(),
data,
weights,
subset,
na.action = NULL,
offset = NULL,
model = TRUE,
algorithm = c("sampling", "meanfield", "fullrank"),
x = FALSE,
y = TRUE,
contrasts = NULL,
out_dir = NULL,
...,
prior = default_prior_coef(family),
prior_intercept = default_prior_intercept(family),
prior_aux = exponential(autoscale = TRUE),
prior_PD = FALSE,
mean_PPD = !prior_PD,
sparse = FALSE
)
formula , data , subset |
Same as | |||||||||||
family |
Same as | |||||||||||
na.action , contrasts |
Same as | |||||||||||
model , offset , weights |
Same as | |||||||||||
algorithm |
Argument "sampling" is for MCMC (default), while "meanfield" and "fullrank" are variational algorithms ("meanfield" is the CmdStan default). | |||||||||||
x |
Logical scalar indicating whether to return the design matrix. | |||||||||||
y |
Logical scalar indicating whether to return the response vector. | |||||||||||
out_dir |
Output directory for model fit environment. | |||||||||||
... |
Further arguments passed to cmdstanr::sample (i.e.,
| |||||||||||
prior |
The prior distribution for the (non-hierarchical) regression coefficients. The default priors are described in the vignette
Prior
Distributions for rstanarm Models.
If not using the default,
See [http://mc-stan.org/rstanarm/reference/priors.html](here) for details
on the families and how to specify the arguments for all of the functions
in the table above.
To omit a prior —i.e., to use a flat (improper) uniform prior—
Note: Unless | |||||||||||
prior_intercept |
The prior distribution for the intercept (after centering all predictors, see note below). The default prior is described in the vignette
Prior
Distributions for rstanarm Models.
If not using the default, Note: If using a dense representation of the design matrix
—i.e., if the | |||||||||||
prior_aux |
The prior distribution for the "auxiliary" parameter (if
applicable). The "auxiliary" parameter refers to a different parameter
depending on the The default prior is described in the vignette
Prior
Distributions for rstanarm Models.
If not using the default, | |||||||||||
prior_PD |
A logical scalar (defaulting to | |||||||||||
mean_PPD |
A logical value indicating whether the sample mean of the
posterior predictive distribution of the outcome should be calculated in
the | |||||||||||
sparse |
A logical scalar (defaulting to |
The cmdstan_glm
function is similar in syntax to
glm
but rather than performing maximum likelihood
estimation of generalized linear models, full Bayesian estimation is
performed (if algorithm
is "sampling"
) via MCMC. The Bayesian
model adds priors (independent by default) on the coefficients of the GLM.
A cmdstanr::CmdStanMCMC()
object.
## Not run:
#' # Linear regression
mtcars$mpg10 <- mtcars$mpg / 10
fit <- cmdstan_glm(
mpg10 ~ wt + cyl + am,
data = mtcars,
# for speed of example only (default is "sampling")
algorithm = "fullrank",
refresh = 0
)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.