mice.impute.2l.lmer: Imputation of a Continuous or a Binary Variable From a...

Description Usage Arguments Value Author(s) References See Also Examples

View source: R/mice.impute.2l.lmer.R

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
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.

Author(s)

Simon Grund, Alexander Robitzsch

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 for normally distributed variables. The function mice::mice.impute.2l.norm allows for residual variances which are allowed to vary across groups while mice::mice.impute.2l.pan assumes homogeneous residual variances.

The micemd package provides further imputation methods for the mice package for imputing multilevel data with fully conditional specification. The function micemd::mice.impute.2l.jomo has similar functionality like mice::mice.impute.2l.pan and imputes normally distributed two-level data with a Bayesian MCMC approach, but relies on the jomo package instead of the pan package. The function micemd::mice.impute.2l.glm.norm has similar functionality like mice.impute.2l.continuous and imputes normally distributed two-level data. The function micemd::mice.impute.2l.glm.bin has similar functionality like mice.impute.2l.binary and imputes binary two-level data.

The hmi package imputes single-level and multilevel data and is also based on fully conditional specification. The package relies on the MCMC estimation implemented in the MCMCglmm package. The imputation procedure can be run with the hmi::hmi function.

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

 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
## 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)

miceadds documentation built on Aug. 9, 2017, 5:04 p.m.