% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/formula-re.R
\name{mm}
\alias{mm}
\title{Set up multi-membership grouping terms in \pkg{brms}}
\usage{
mm(
  ...,
  weights = NULL,
  scale = TRUE,
  by = NULL,
  cor = TRUE,
  id = NA,
  cov = NULL,
  dist = "gaussian"
)
}
\arguments{
\item{...}{One or more terms containing grouping factors.}

\item{weights}{A matrix specifying the weights of each member.
It should have as many columns as grouping terms specified in \code{...}.
If \code{NULL} (the default), equally weights are used.}

\item{scale}{Logical; if \code{TRUE} (the default),
weights are standardized in order to sum to one per row.
If negative weights are specified, \code{scale} needs
to be set to \code{FALSE}.}

\item{by}{An optional factor matrix, specifying sub-populations of the
groups. It should have as many columns as grouping terms specified in
\code{...}. For each level of the \code{by} variable, a separate
variance-covariance matrix will be fitted. Levels of the grouping factor
must be nested in levels of the \code{by} variable matrix.}

\item{cor}{Logical. If \code{TRUE} (the default), group-level terms will be
modelled as correlated.}

\item{id}{Optional character string. All group-level terms across the model
with the same \code{id} will be modeled as correlated (if \code{cor} is
\code{TRUE}). See \code{\link{brmsformula}} for more details.}

\item{cov}{An optional matrix which is proportional to the withon-group
covariance matrix of the group-level effects. All levels of the grouping
factor should appear as rownames of the corresponding matrix. This argument
can be used, among others, to model pedigrees and phylogenetic effects. See
\code{vignette("brms_phylogenetics")} for more details. By default, levels
of the same grouping factor are modeled as independent of each other.}

\item{dist}{Name of the distribution of the group-level effects.
Currently \code{"gaussian"} is the only option.}
}
\description{
Function to set up a multi-membership grouping term in \pkg{brms}.
The function does not evaluate its arguments --
it exists purely to help set up a model with grouping terms.
}
\examples{
\dontrun{
# simulate some data
dat <- data.frame(
 y = rnorm(100), x1 = rnorm(100), x2 = rnorm(100),
 g1 = sample(1:10, 100, TRUE), g2 = sample(1:10, 100, TRUE)
)

# multi-membership model with two members per group and equal weights
fit1 <- brm(y ~ x1 + (1|mm(g1, g2)), data = dat)
summary(fit1)

# weight the first member two times for than the second member
dat$w1 <- rep(2, 100)
dat$w2 <- rep(1, 100)
fit2 <- brm(y ~ x1 + (1|mm(g1, g2, weights = cbind(w1, w2))), data = dat)
summary(fit2)

# multi-membership model with level specific covariate values
dat$xc <- (dat$x1 + dat$x2) / 2
fit3 <- brm(y ~ xc + (1 + mmc(x1, x2) | mm(g1, g2)), data = dat)
summary(fit3)
}

}
\seealso{
\code{\link{brmsformula}}, \code{\link{mmc}}
}
