Skip to contents

lme4::glmer but with multimembership random effects

Usage

glmer(
  formula,
  data = NULL,
  family,
  control = lme4::glmerControl(),
  start = NULL,
  verbose = 0L,
  nAGQ = 1L,
  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.

data

an optional data frame containing the variables named in formula. By default the variables are taken from the environment from which lmer is called. While data is optional, the package authors strongly recommend its use, especially when later applying methods such as update and drop1 to the fitted model (such methods are not guaranteed to work properly if data is omitted). If data is omitted, variables will be taken from the environment of formula (if specified as a formula) or from the parent frame (if specified as a character vector).

family

a GLM family, see glm and family.

control

a list (of correct class, resulting from lmerControl() or glmerControl() 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, or a numeric vector. A numeric start argument will be used as the starting value of theta. If start is a list, the theta element (a numeric vector) is used as the starting value for the first optimization step (default=1 for diagonal elements and 0 for off-diagonal elements of the lower Cholesky factor); the fitted value of theta from the first step, plus start[["fixef"]], are used as starting values for the second optimization step. If start has both fixef and theta elements, the first optimization step is skipped. For more details or finer control of optimization, see modular.

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.

nAGQ

integer scalar - the number of points per axis for evaluating the adaptive Gauss-Hermite approximation to the log-likelihood. Defaults to 1, corresponding to the Laplace approximation. Values greater than 1 produce greater accuracy in the evaluation of the log-likelihood at the expense of speed. A value of zero uses a faster but less exact form of parameter estimation for GLMMs by optimizing the random effects and the fixed-effects coefficients in the penalized iteratively reweighted least squares step. (See Details.)

weights

an optional vector of ‘prior weights’ to be used in the fitting process. Should be NULL or a numeric vector.

na.action

a function that indicates what should happen when the data contain NAs. The default action (na.omit, inherited from the ‘factory fresh’ value of getOption("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 more offset terms can be included in the formula instead or as well, and if more than one is specified their sum is used. See model.offset.

contrasts

an optional list. See the contrasts.arg of model.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

Value

lme4 model object

Examples


df <- data.frame(
  x = runif(60, 0, 1),
  y = rbinom(60, 1, 0.6),
  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
glmer(y ~ x + (1 | members),
  data = df,
  family = binomial,
  memberships = list(members = weights)
)
#> Generalized linear mixed model fit by maximum likelihood (Laplace
#>   Approximation) [glmerModMultiMember]
#>  Family: binomial  ( logit )
#> Formula: y ~ x + (1 | members)
#>    Data: df
#>      AIC      BIC   logLik deviance df.resid 
#>  83.4162  89.6992 -38.7081  77.4162       57 
#> Random effects:
#>  Groups  Name        Std.Dev.
#>  members (Intercept) 0       
#> Number of obs: 60, groups:  members, 3
#> Fixed Effects:
#> (Intercept)            x  
#>      0.3690       0.4972