lme4::lmer but with multimembership random effects
Usage
lmer(
formula,
data = NULL,
REML = TRUE,
control = lme4::lmerControl(),
start = NULL,
verbose = 0L,
weights = NULL,
na.action = na.omit,
offset = NULL,
contrasts = NULL,
devFunOnly = FALSE,
memberships = NULL
)
Arguments
- formula
a two-sided linear formula object describing both the fixed-effects and random-effects part of the model, with the response on the left of a
~
operator and the terms, separated by+
operators, on the right. Random-effects terms are distinguished by vertical bars (|
) separating expressions for design matrices from grouping factors. Two vertical bars (||
) can be used to specify multiple uncorrelated random effects for the same grouping variable. (Because of the way it is implemented, the||
-syntax works only for design matrices containing numeric (continuous) predictors; to fit models with independent categorical effects, seedummy
or thelmer_alt
function from the afex package.)- data
an optional data frame containing the variables named in
formula
. By default the variables are taken from the environment from whichlmer
is called. Whiledata
is optional, the package authors strongly recommend its use, especially when later applying methods such asupdate
anddrop1
to the fitted model (such methods are not guaranteed to work properly ifdata
is omitted). Ifdata
is omitted, variables will be taken from the environment offormula
(if specified as a formula) or from the parent frame (if specified as a character vector).- REML
logical scalar - Should the estimates be chosen to optimize the REML criterion (as opposed to the log-likelihood)?
- control
a list (of correct class, resulting from
lmerControl()
orglmerControl()
respectively) containing control parameters, including the nonlinear optimizer to be used and parameters to be passed through to the nonlinear optimizer, see the*lmerControl
documentation for details.- start
a named
list
of starting values for the parameters in the model. Forlmer
this can be a numeric vector or a list with one component named"theta"
.- verbose
integer scalar. If
> 0
verbose output is generated during the optimization of the parameter estimates. If> 1
verbose output is generated during the individual penalized iteratively reweighted least squares (PIRLS) steps.- weights
an optional vector of ‘prior weights’ to be used in the fitting process. Should be
NULL
or a numeric vector. Priorweights
are not normalized or standardized in any way. In particular, the diagonal of the residual covariance matrix is the squared residual standard deviation parametersigma
times the vector of inverseweights
. Therefore, if theweights
have relatively large magnitudes, then in order to compensate, thesigma
parameter will also need to have a relatively large magnitude.- na.action
a function that indicates what should happen when the data contain
NA
s. The default action (na.omit
, inherited from the 'factory fresh' value ofgetOption("na.action")
) strips any observations with any missing values in any variables.- offset
this can be used to specify an a priori known component to be included in the linear predictor during fitting. This should be
NULL
or a numeric vector of length equal to the number of cases. One or moreoffset
terms can be included in the formula instead or as well, and if more than one is specified their sum is used. Seemodel.offset
.- contrasts
an optional list. See the
contrasts.arg
ofmodel.matrix.default
.- devFunOnly
logical - return only the deviance evaluation function. Note that because the deviance function operates on variables stored in its environment, it may not return exactly the same values on subsequent calls (but the results should always be within machine tolerance).
- memberships
named list of weight matrices that will replace any (dummy) random effects with matching names
Examples
df <- data.frame(
x = seq(60) + runif(60, 0, 10),
y = seq(60) + rep(runif(6, 0, 10), 10),
memberships = rep(c("a,b,c", "a,c", "a", "b", "b,a", "b,c,a"), 10)
)
weights <- weights_from_vector(df$memberships)
# note that the grouping variable name is arbitrary -- it just has
# to match the name in the list and doesn't need to correspond to a column
# name in the data
lmer(y ~ x + (1 | members),
data = df,
memberships = list(members = weights)
)
#> Linear mixed model fit by REML ['lmerModMultiMember']
#> Formula: y ~ x + (1 | members)
#> Data: df
#> REML criterion at convergence: 334.1473
#> Random effects:
#> Groups Name Std.Dev.
#> members (Intercept) 4.081e-07
#> Residual 3.827e+00
#> Number of obs: 60, groups: members, 3
#> Fixed Effects:
#> (Intercept) x
#> -0.2640 0.9876