mice.impute.2l.contextual.pmm | R Documentation |
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.
mice.impute.2l.contextual.pmm(y, ry, x, type, imputationWeights=NULL,
interactions=NULL, quadratics=NULL, pls.facs=NULL, ...)
mice.impute.2l.contextual.norm(y, ry, x, type, ridge=10^(-5),
imputationWeights=NULL, interactions=NULL, quadratics=NULL, pls.facs=NULL, ...)
y |
Incomplete data vector of length |
ry |
Vector of missing data pattern ( |
x |
Matrix ( |
type |
Type of predictor variables. |
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 |
pls.facs |
Number of factors used in partial least dimension reduction (if requested) |
... |
Further arguments to be passed |
ridge |
Ridge parameter in the diagonal of |
A vector of length nmis=sum(!ry)
with imputed values.
For imputations at level 2 variables see
mice::mice.impute.2lonly.norm
and mice::mice.impute.2lonly.pmm
.
## Not run:
#############################################################################
# EXAMPLE 1: Sequential hierarchical imputation for data.ma05 dataset
#############################################################################
data(data.ma05)
dat <- data.ma05
# define predictor matrix
predM <- mice::make.predictorMatrix(data=dat)
# exclude student IDs
predM[, "idstud"] <- 0
# define idclass as the cluster variable (type=-2)
predM[, "idclass" ] <- -2
# initialize with norm method
impMethod <- mice::make.method(data=dat)
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,
method=impMethod, paniter=100)
summary(imp)
#**** imputation model 2 with PLS dimension reduction
# define some interaction effects
interactions <- list( manote=c("migrant", "misei") )
# number of PLS factors (5 factors)
pls.facs <- list( manote=5 )
# do imputation
imp2 <- mice::mice( dat, predictorMatrix=predM, interactions=interactions,
pls.facs=pls.facs, method=impMethod, paniter=100)
summary(imp2)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.