Description Usage Arguments Details Value Author(s) Examples
Implements a survey weighted mixed-effects model using the provided formula.
1 2 3 4 |
formula |
a formula object in the style of |
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:
|
center_grand |
a formula of variable names to be grand mean centered, for example to center the variable education by overall mean of
education: |
robustSE |
logical, defaults to |
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; |
verbose |
logical, default |
acc0 |
integer, the precision of |
keepAdapting |
logical, set to |
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 |
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:
Standard errors of random effect variances are robust unless robustSE is set to false; see vignette for details.
To see the function that is maximized in the estimation of this model; see the section on "Model fitting" in the Introduction to Mixed Effect Models with WeMix 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.
If starting coefficients are not provided they are estimated using lme4
.
For non linear models, when the variance of a random effect is very low (<.1), WeMix doesn't estimate it, because very low variances create problems with numerical evaluation. In these cases, consider estimating without that random effect.
The model is estimated by maximum likelihood estimation.
To choose number of quadrature points for non-linear model evaluation, 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.
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.
ranefs - group level random effects.
SE - the standard errors of the fixed effects, robust if robustSE was set to true.
vars - numeric vector, the random effect variances.
theta - the theta vector.
call - the original call used.
levels - integer, the number of levels in the model.
ICC - numeric, the Intraclass Correlation Coefficient.
CMODE - the conditional mean of the random effects.
invHessian - inverse of the the second derivative of the likelihood function.
ICC - the interclass correlation.
is_adaptive - logical, indicates if adaptive quadrature was used for estimation.
sigma - the sigma value.
ngroups - the number of observations in each group.
varDF - the variance data frame in the format of the variance data frame returned by lme4.
varVC - the variance-covariance matrix of the random effects.
cov_mat - the variance-covariance matrix of the fixed effects.
Paul Bailey, Claire Kelley, and Trang Nguyen
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.