stan_mvmer | R Documentation |
Bayesian inference for multivariate GLMs with group-specific coefficients that are assumed to be correlated across the GLM submodels.
stan_mvmer(
formula,
data,
family = gaussian,
weights,
prior = normal(autoscale = TRUE),
prior_intercept = normal(autoscale = TRUE),
prior_aux = cauchy(0, 5, autoscale = TRUE),
prior_covariance = lkj(autoscale = TRUE),
prior_PD = FALSE,
algorithm = c("sampling", "meanfield", "fullrank"),
adapt_delta = NULL,
max_treedepth = 10L,
init = "random",
QR = FALSE,
sparse = FALSE,
...
)
formula |
A two-sided linear formula object describing both the
fixed-effects and random-effects parts of the longitudinal submodel
similar in vein to formula specification in the lme4 package
(see |
data |
A data frame containing the variables specified in
|
family |
The family (and possibly also the link function) for the
GLM submodel(s). See |
weights |
Same as in |
prior , prior_intercept , prior_aux |
Same as in |
prior_covariance |
Cannot be |
prior_PD |
A logical scalar (defaulting to |
algorithm |
A string (possibly abbreviated) indicating the
estimation approach to use. Can be |
adapt_delta |
Only relevant if |
max_treedepth |
A positive integer specifying the maximum treedepth
for the non-U-turn sampler. See the |
init |
The method for generating initial values. See
|
QR |
A logical scalar defaulting to |
sparse |
A logical scalar (defaulting to |
... |
Further arguments passed to the function in the rstan
package ( Another useful argument that can be passed to rstan via |
The stan_mvmer
function can be used to fit a multivariate
generalized linear model (GLM) with group-specific terms. The model consists
of distinct GLM submodels, each which contains group-specific terms; within
a grouping factor (for example, patient ID) the grouping-specific terms are
assumed to be correlated across the different GLM submodels. It is
possible to specify a different outcome type (for example a different
family and/or link function) for each of the GLM submodels.
Bayesian estimation of the model is performed via MCMC, in the same way as
for stan_glmer
. Also, similar to stan_glmer
,
an unstructured covariance matrix is used for the group-specific terms
within a given grouping factor, with priors on the terms of a decomposition
of the covariance matrix.See priors
for more information about
the priors distributions that are available for the covariance matrices,
the regression coefficients and the intercept and auxiliary parameters.
A stanmvreg object is returned.
stan_glmer
, stan_jm
,
stanreg-objects
, stanmvreg-methods
,
print.stanmvreg
, summary.stanmvreg
,
posterior_predict
, posterior_interval
.
if (.Platform$OS.type != "windows" || .Platform$r_arch !="i386") {
#####
# A multivariate GLM with two submodels. For the grouping factor 'id', the
# group-specific intercept from the first submodel (logBili) is assumed to
# be correlated with the group-specific intercept and linear slope in the
# second submodel (albumin)
f1 <- stan_mvmer(
formula = list(
logBili ~ year + (1 | id),
albumin ~ sex + year + (year | id)),
data = pbcLong,
# this next line is only to keep the example small in size!
chains = 1, cores = 1, seed = 12345, iter = 1000)
summary(f1)
#####
# A multivariate GLM with one bernoulli outcome and one
# gaussian outcome. We will artificially create the bernoulli
# outcome by dichotomising log serum bilirubin
pbcLong$ybern <- as.integer(pbcLong$logBili >= mean(pbcLong$logBili))
f2 <- stan_mvmer(
formula = list(
ybern ~ year + (1 | id),
albumin ~ sex + year + (year | id)),
data = pbcLong,
family = list(binomial, gaussian),
chains = 1, cores = 1, seed = 12345, iter = 1000)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.