data(studentratings)
fml <- ReadDis + SES ~ ReadAchiev + (1|ID)
imp <- panImpute(studentratings, formula=fml, n.burn=1000, n.iter=100, m=5)
implist <- mitmlComplete(imp, print=1:5)
# * Example 1: data manipulation
# calculate and save cluster means
new1.implist <- within(implist, Means.ReadAchiev <- clusterMeans(ReadAchiev, ID))
# calculate interaction terms
new2.implist <- within(implist, int.SesCa <- SES*CognAbility )
# * Example 2: fitting statistical models
# fit regression model
fit.lm <- with(implist, lm(ReadAchiev ~ ReadDis))
# fit multilevel model using lme4
require(lme4)
fit.lmer <- with(implist, lmer(ReadAchiev ~ ReadDis + (1|ID)))
# * Example 3: manual extraction of variance estimates
require(lme4)
fit.lmer <- with(implist, lmer(SES ~ (1|ID)))
# extract level-1 and level-2 variances
var.l1 <- sapply(fit.lmer, function(z) attr(VarCorr(z),"sc")^2)
var.l2 <- sapply(fit.lmer, function(z) VarCorr(z)$ID[1,1])
# calculate final estimate of the intraclass correlation
ICC <- mean( var.l2 / (var.l2+var.l1) )
Run the code above in your browser using DataLab