Learn R Programming

miceadds (version 2.2-0)

mice.impute.2l.contextual.pmm: Imputation by Predictive Mean Matching with Contextual Variables

Description

This imputation method imputes a variable using linear regression with predictive mean matching as the imputation method. Including a contextual effects means that an aggregated variable at a cluster level is included as a further covariate.

Usage

mice.impute.2l.contextual.pmm(y, ry, x, type, imputationWeights = NULL, interactions = NULL, quadratics = 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 covariates.
type
Type of predictor variables. type=-2 refers to the cluster variable, type=2 denotes a variable for which also a contextual effect is included and type=1 denotes all other variables which are included as 'ordinary' predictors.
imputationWeights
Optional vector of sample weights
interactions
Vector of variable names used for creating interactions
quadratics
Vector of variable names used for creating quadratic terms
...
Further arguments to be passed

Value

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

See Also

For imputations at level 2 variables see mice::mice.impute.2lonly.norm and mice::mice.impute.2lonly.pmm.

Examples

Run this code
## Not run: 
# #############################################################################
# # EXAMPLE 1: Sequential hierarchical imputation for data.ma05 dataset
# #############################################################################
# 
# data(data.ma05)
# dat <- data.ma05
# 
# # empty imputation
# imp0 <- mice::mice( dat , m=0 , maxit=0 )
# summary(imp0)
# 
# # define predictor matrix
# predM <- imp0$pred
# # exclude student IDs
# predM[ , "idstud"] <- 0
# # define idclass as the cluster variable (type=-2)
# predM[ , "idclass" ] <- -2  
# 
# # initialize with norm method
# impMethod <- rep( "norm" , length(imp0$method) )
# names(impMethod) <- names( imp0$method )
# impMethod[ c("idstud","idclass")] <- ""
# 
# #*****
# # STUDENT LEVEL (Level 1)
# 
# # Use a random slope model for Dscore and Mscore as the imputation method.
# # Here, variance homogeneity of residuals is assumed (contrary to
# # the 2l.norm imputation method in the mice package).
# impMethod[ c("Dscore" , "Mscore") ] <- "2l.pan"
# predM[ c("Dscore","Mscore") , "misei" ] <- 2	# random slopes on 'misei'
# predM[  , "idclass" ] <- -2
# 
# # For imputing 'manote' and 'denote' use contextual effects (i.e. cluszer means)
# # of variables 'misei' and 'migrant'
# impMethod[ c("denote" , "manote") ] <- "2l.contextual.pmm"
# predM[ c("denote" , "manote") , c("misei","migrant")] <- 2
# 
# # Use no cluster variable 'idclass' for imputation of 'misei'
# impMethod[ "misei"] <- "norm"
# predM[ "misei" , "idclass"] <- 0 # use no multilevel imputation model
# 
# # Variable migrant: contextual effects of Dscore and misei
# impMethod[ "migrant"] <- "2l.contextual.pmm"
# predM[ "migrant" , c("Dscore" ,  "misei" ) ] <- 2
# predM[ "migrant" , "idclass" ] <- -2
# 
# #****
# # CLASS LEVEL (Level 2)
# # impute 'sprengel' and 'groesse' at the level of classes
# impMethod[ "sprengel"] <- "2lonly.pmm"
# impMethod[ "groesse"] <- "2lonly.norm"
# predM[ c("sprengel","groesse") , "idclass" ] <- -2
# 
# # do imputation
# imp <- mice::mice( dat , predictorMatrix = predM , m = 3 ,  maxit = 4 ,
#            imputationMethod = impMethod  , paniter=100)           
# summary(imp)
# ## End(Not run)

Run the code above in your browser using DataLab