mix: Survey Weighted Mixed-Effects Models

Description Usage Arguments Details Value Author(s) Examples

View source: R/adaptiveQuad.R

Description

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

Usage

1
2
3
4
mix(formula, data, weights, center_group = NULL, center_grand = NULL,
  robustSE = TRUE, max_iteration = 10, nQuad = 13L, run = TRUE,
  verbose = FALSE, acc0 = 120, keepAdapting = FALSE, start = NULL,
  fast = FALSE, family = 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 names of weight variables found in data frame.

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.

robustSE

logical, defaults to TRUE indicating whether robust standard errors should be estimated.

max_iteration

a optional integer, for non-linear models fit by adaptive quadrature how many iteration should be allowed before quitting. Defaults to 10. This is used because if the liklihood surface is flat, This is used because if the likelihood surface is flat, models may run for a very long time without converging.

nQuad

an optional integer number of quadrature point to evaluate models solved by adaptive quadrature. Only non-linear models are evaluated with adaptive quadrature. See notes for additional guidelines.

run

logical; TRUE runs the model while FALSE provides partial output for debugging or testing. Only applies to non-linear models evaluated by adaptive quadrature.

verbose

logical, default FALSE; set to TRUE to print results of intermediate steps of adaptive quadrature. Only applies to non-linear models.

acc0

integer, the precision of mpfr, default 120. Only applies to non-linear models.

keepAdapting

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

start

optional 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; deprecated

family

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

Details

Linear models are solved using a modification of the analytic solution developed by Bates and Pinheiro (Bates & Pinheiro, 1998). Non-linear models are solved using adaptive quadrature following the method in Stata's GLAMMM (Rabe-Hesketh & Skrondal, 2006). For additional details, see the vignettes Weighted Mixed Models: Adaptive Quadrature and Weighted Mixed Models: Analytical Solution which provide extensive examples as well as a description of the mathematical basis of the estimation procedure and comparisons to model specifications in other common software.

Notes:

Value

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

Author(s)

Paul Bailey, Claire Kelley, and Trang Nguyen

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
## Not run: 
library(WeMix)
library(lme4)

data(sleepstudy)
ss1 <- sleepstudy
#add group variables for 3 level model 
ss1$Group <- 1
ss1$Group <- ifelse(ss1$Subject %in% c(349,335,330, 352, 337, 369), 2, ss1$Group)

# Create weights
ss1$W1 <- ifelse(ss1$Subject %in% c(308, 309, 310), 2, 1)
ss1$W2 <- 1
ss1$W3 <- ifelse(ss1$Group == 2,2,1 )

# Run random-intercept 2-level model 
two_level <- mix(Reaction~ Days + (1|Subject),data=ss1, weights = c("W1","W2"))

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

 #Run three level model with random slope and intercept. 
 three_level <- mix(Reaction~ Days + (1|Subject) + (1+Days|Group),data=ss1, 
 weights = c("W1","W2","W3"))

## End(Not run)

ClaireKelley/WeMix documentation built on May 21, 2019, 6:46 a.m.