WeMix (version 2.2.1)

mix: Survey Weighted Mixed-Effects Models

Description

Implements a survey weighted mixed-effects model using the provided formula.

Usage

mix(formula, data, weights, nQuad = 13L, run = TRUE, verbose = TRUE,
  acc0 = 120, keepAdapting = FALSE, start = NULL, fast = FALSE,
  family = NULL, center_group = NULL, center_grand = NULL)

Arguments

formula

a formula object in the style of lme4 that creates the model.

data

a data frame containing the raw data for the model.

weights

a character vector of weight variables found in data frame.

nQuad

an integer number of quadrature point to evaluate on. See notes for guidelines.

run

logical; TRUE runs the model why FALSE provides partial output for debugging or testing.

verbose

logical, default FALSE; set to TRUE to print results of intermediate steps

acc0

integer, the precision of mpfr, default 120

keepAdapting

logical, set to TRUE when the adaptive quadrature should adapt after every Newton step. Defaults to TRUE. FALSE should be used rarely for faster (but less accurate) results.

start

numeric vector representing the point at which the model should start optimization; takes the shape of c(coef, vars) from results (see help).

fast

logical; use c++ function for faster result. Defaults to TRUE.

family

the family; optionally used to specify generalized linear mixed models. Currently only binomial(link="logit") is supported.

center_group

a list where the name of each element is the name of the aggregation level, and the element is a formula of variable names to be group mean centered, for example to group mean center gender and age with in the group student: list("student"= ~gender+age), default value of NULL does not perform any group mean centering.

center_grand

a formula of variable names to be grand mean centered, for example to center the variable education by overall mean of education: ~education. Default is NULL which does no centering

Value

object of class WeMixResults. This is a list with objects:

  • lnlf - function, the likelihood function

  • lnl - numeric, the logliklihood of the model

  • coef - numeric vector, the estimated coefficients of the model

  • vars- numeric vector, the variances

  • call - the original call used

  • levels - integer, the number of levels in the model

  • ICC - numeric, the Intraclass Correlation Coefficient

  • CMEAN - function the conditional mode function that can be called with par and omega to get the conditional mode of the likelihood function

  • CMODE - function the conditional mean function that can be called with par and omega to get the conditional mean of the likelihood function

  • Hessian - the second derivative of the likelihood function

Details

Uses adaptive quadrature following the method in Stata's GLAMMM. For additional details, see the vignette Weighted Mixed Models which provides extensive examples as well as a description of the mathematical basis of the estimation procedure. The main specification also shows comparisons to model specifications in other common software.

Notes:

  • Standard errors of random effect variances are estimated by the Sandwich Method; see main vignette for details.

  • To see the function that is maximized in the estimation of this model; see the section on "Model fitting" in the main vignette.

  • When all weights above the individual level are 1, this is similar to a lmer and you should use lme4 because it is much faster.

  • Starting coefficients are not provided they are estimated using lme4.

  • When the variance of a random effect is very low (<.1), we don't estimate it because very low variances create problems with numerical evaluation. In these cases, consider estimating without that RE.

  • The model is estimated by maximum likelihood estimation, restricted maximum likelihood (REML) is not available.

  • To choose number of quadrature points, a balance is needed between accuracy and speed- estimation time increases quadratically with the number of points chosen. In addition, an odd number of points is traditionally used. We recommend starting at 13 and increasing or decreasing as needed.

Examples

Run this code
# NOT RUN {
library(WeMix)
library(lme4)

data(sleepstudy)
ss1 <- sleepstudy
doubles <- c(308, 309, 310) # subject with double obs
# Create weights
ss1$W1 <- ifelse(ss1$Subject %in% doubles, 2, 1)
ss1$W2 <- 1

# Run random-intercept 2-level model 
mix1 <- mix(Reaction~ Days + (1|Subject),data=ss1, weights = c("W1","W2"),
            fast=TRUE, nQuad=13, verbose=FALSE)

# Run random-intercept 2-level model with group-mean centering
grp_centered <- mix(Reaction ~ Days + (1|Subject), data=ss1, weights = c("W1","W2"), nQuad=13,
          fast=TRUE, center_group = list("Subject" = ~Days),
          verbose=FALSE)
# }

Run the code above in your browser using DataLab