Learn R Programming

miceadds (version 2.2-0)

mice.impute.2l.lmer: Imputation of a Continuous or a Binary Variable From a Two-Level Regression Model using lme4 or blme

Description

The function mice.impute.2l.continuous imputes values of continuous variables with a linear mixed effects model using lme4::lmer or blme::blmer. The lme4::lmer or blme::blmer function is also used for predictive mean matching where the match is based on predicted values which contain the fixed and (sampled) random effects. Binary variables can be imputed from a two-level logistic regression model fitted with the lme4::glmer or blme::bglmer function. See Snijders and Bosker (2012) and Zinn (2013) for details.

Usage

mice.impute.2l.continuous(y, ry, x, type, intercept=TRUE, groupcenter.slope=FALSE, draw.fixed=TRUE, random.effects.shrinkage=1E-6, glmer.warnings=TRUE, blme_use = FALSE , blme_args = NULL , ... )
mice.impute.2l.pmm(y, ry, x, type, intercept=TRUE, groupcenter.slope=FALSE, draw.fixed=TRUE, random.effects.shrinkage=1E-6, glmer.warnings=TRUE, donors = 5 , match_sampled_pars = TRUE , blme_use = FALSE , blme_args = NULL , ... ) mice.impute.2l.binary(y, ry, x, type, intercept=TRUE, groupcenter.slope=FALSE, draw.fixed=TRUE, random.effects.shrinkage=1E-6, glmer.warnings=TRUE, blme_use = FALSE , blme_args = NULL , ... )

Arguments

y
Incomplete data vector of length n
ry
Vector of missing data pattern (FALSE -- missing, TRUE -- observed)
x
Matrix (n x p) of complete predictors.
type
Type of predictor variable. The cluster identifier has type -2, fixed effects predictors without a random slope type 1 and predictors with fixed effects and random effects have type 2.
intercept
Optional logical indicating whether the intercept should be included.
groupcenter.slope
Optional logical indicating whether covariates should be centered around group means
draw.fixed
Optional logical indicating whether fixed effects parameter should be randomly drawn
random.effects.shrinkage
Shrinkage parameter for stabilizing the covariance matrix of random effects
glmer.warnings
Optional logical indicating whether warnings from glmer should be displayed
blme_use
Logical indicating whether the blme package should be used.
blme_args
(Prior) Arguments for blme, see blme::blmer and blme::bmerDist-class.
donors
Number of donors used for predictive mean matching
match_sampled_pars
Logical indicating whether values of nearest neighbors should also be sampled in pmm imputation.
...
Further arguments to be passed

Value

A vector of length nmis=sum(!ry) with imputed values.

References

Snijders, T. A. B., & Bosker, R. J. (2012). Multilevel analysis: An introduction to basic and advanced multilevel modeling. Thousand Oaks, CA: Sage.

Zinn, S. (2013). An imputation model for multilevel binary data. NEPS Working Paper No 31.

See Also

See mice::mice.impute.2l.norm and mice::mice.impute.2l.pan for imputation functions in the mice package under fully conditional specification.

See the pan (pan::pan) and the jomo (jomo::jomo) package for joint multilevel imputation. See mitml::panImpute and mitml::jomoImpute for wrapper functions to these packages in the mitml package.

Examples

Run this code
## Not run: 
# #############################################################################
# # EXAMPLE 1: Imputation of a binary variable
# #############################################################################
# 
# #--- simulate missing values
# set.seed(976)
# G <- 30		# number of groups
# n <- 8		# number of persons per group
# iccx <- .2	# intra-class correlation X
# iccy <- .3	# latent intra-class correlation binary outcome
# bx <- .4	# regression coefficient
# threshy <- stats::qnorm(.70)  # threshold for y
# x <- rep( rnorm( G , sd = sqrt( iccx) ) , each=n )  +
#             rnorm(G*n , sd = sqrt( 1 - iccx) )
# y <- bx * x + rep( rnorm( G , sd = sqrt( iccy) ) , each=n )  +
#                 rnorm(G*n , sd = sqrt( 1 - iccy) )
# y <- 1 * ( y > threshy )
# dat <- data.frame( group = 100+rep(1:G , each=n) , x = x , y = y )
# 
# #* create some missings
# dat1 <- dat
# dat1[ seq( 1 , G*n , 3 ) ,"y" ]  <- NA
# dat1[ dat1$group == 2 , "y" ] <- NA
# 
# #--- prepare imputation in mice
# vars <- colnames(dat1)
# V <- length(vars)
# #* predictor matrix
# predmat <- matrix( 0 , nrow=V , ncol=V)
# rownames(predmat) <- colnames(predmat) <- vars
# predmat["y" , ] <- c(-2,2,0)
# #* imputation methods
# impmeth <- rep("",V)
# names(impmeth) <- vars
# impmeth["y"] <- "2l.binary"
# 
# #** imputation with logistic regression ('2l.binary')
# imp1 <- mice::mice( data = as.matrix(dat1) , imputationMethod = impmeth ,
#                 predictorMatrix = predmat , maxit = 1 , m = 5 )
# #** imputation with predictive mean matching ('2l.pmm')
# impmeth["y"] <- "2l.pmm"
# imp2 <- mice::mice( data = as.matrix(dat1) , imputationMethod = impmeth ,
#                 predictorMatrix = predmat , maxit = 1 , m = 5 )
#                 
# #** imputation with logistic regression using blme package                 
# blme_args <- list( "cov.prior" = "invwishart")
# imp3 <- mice::mice( data = as.matrix(dat1) , imputationMethod = impmeth ,
#                 predictorMatrix = predmat , maxit = 1 , m = 5 , 
#                 blme_use = TRUE , blme_args = blme_args )
# ## End(Not run)

Run the code above in your browser using DataLab