require(lme4)
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 (parallel calculation) [time consumming]
#res.mice <- mice.par(CHEM97Na, predictorMatrix = predictor.matrix,
# method=method)
#check convergence
#plot(res.mice)
#analysis (apply a generalized linear mixed effects model to each imputed dataset)
#ana <- with(res.mice, expr=glmer(Score~Sex+GSCE+(1|School),
# family="poisson",
# control=glmerControl(optimizer = "bobyqa")))
#check the number of generated tables
#plot(ana)
#pooling
#res.pool <- pool(ana)
#summary(res.pool)
Run the code above in your browser using DataLab