require(parallel)
nnodes<-detectCores()-1#number of nodes
m<-1000#nb generated values per observation
################
#one level data
################
require(mice)
data(nhanes)
#res.mice<-mice.par(nhanes,m = m,nnodes = nnodes)
#res.over<-overimpute(res.mice, nnodes = nnodes)
################
#two level data (time consumming)
################
data(CHEM97Na)
ind.clust<-1#index for the cluster variable
#initialisation of the argument predictorMatrix
predictor.matrix<-mice(CHEM97Na,m=1,maxit=0)$pred
predictor.matrix[ind.clust,ind.clust]<-0
predictor.matrix[-ind.clust,ind.clust]<- -2
predictor.matrix[predictor.matrix==1]<-2
#initialisation of the argument method
method<-find.defaultMethod(CHEM97Na,ind.clust)
#multiple imputation by chained equations (time consumming)
#res.mice<-mice.par(CHEM97Na,
# predictorMatrix = predictor.matrix,
# method=method,m=m,nnodes = nnodes)
#overimputation on 30 individuals
#res.over<-overimpute(res.mice,
# nnodes=nnodes,
# plotinds=sample(x = seq(nrow(CHEM97Na)),size = 30))
Run the code above in your browser using DataLab