# NOTE: The number of iterations in these examples is much lower than it
# should be! This is done in order to comply with CRAN policies, and more
# iterations are recommended for applications in practice!
data(studentratings)
# *** ................................
# the 'type' interface
#
# * Example 1.1: 'ReadDis' and 'SES', predicted by 'ReadAchiev' and
# 'CognAbility', with random slope for 'ReadAchiev'
type <- c(-2,0,0,0,0,0,3,1,2,0)
names(type) <- colnames(studentratings)
type
imp <- jomoImpute(studentratings, type=type, n.burn=100, n.iter=10, m=5)
# * Example 1.2: 'ReadDis' and 'SES' groupwise for 'FedState',
# and predicted by 'ReadAchiev'
type <- c(-2,-1,0,0,0,0,2,1,0,0)
names(type) <- colnames(studentratings)
type
imp <- jomoImpute(studentratings, type=type, n.burn=100, n.iter=10, m=5)
# *** ................................
# the 'formula' interface
#
# * Example 2.1: imputation of 'ReadDis', predicted by 'ReadAchiev'
# (random intercept)
fml <- ReadDis ~ ReadAchiev + (1|ID)
imp <- jomoImpute(studentratings, formula=fml, n.burn=100, n.iter=10, m=5)
# ... the intercept can be suppressed using '0' or '-1' (here for fixed intercept)
fml <- ReadDis ~ 0 + ReadAchiev + (1|ID)
imp <- jomoImpute(studentratings, formula=fml, n.burn=100, n.iter=10, m=5)
# * Example 2.2: imputation of 'ReadDis', predicted by 'ReadAchiev'
# (random slope)
fml <- ReadDis ~ ReadAchiev + (1+ReadAchiev|ID)
imp <- jomoImpute(studentratings, formula=fml, n.burn=100, n.iter=10, m=5)
# * Example 2.3: imputation of 'ReadDis', predicted by 'ReadAchiev',
# groupwise for 'FedState'
fml <- ReadDis ~ ReadAchiev + (1|ID)
imp <- jomoImpute(studentratings, formula=fml, group="FedState", n.burn=100,
n.iter=10, m=5)
# * Example 2.4: imputation of 'ReadDis', predicted by 'ReadAchiev'
# including the cluster mean of 'ReadAchiev' as an additional predictor
fml <- ReadDis ~ ReadAchiev + I(clusterMeans(ReadAchiev,ID)) + (1|ID)
imp <- jomoImpute(studentratings, formula=fml, n.burn=100, n.iter=10, m=5)
# ... using 'save.pred' to save the calculated cluster means in the data set
fml <- ReadDis ~ ReadAchiev + I(clusterMeans(ReadAchiev,ID)) + (1|ID)
imp <- jomoImpute(studentratings, formula=fml, n.burn=100, n.iter=10, m=5,
save.pred=TRUE)
head(mitmlComplete(imp,1))
# * Example 2.5: imputation of 'ReadAchiev' and 'MathAchiev' using random
# covariances matrices at level 1 (residuals)
fml <- ReadAchiev + MathAchiev ~ (1|ID)
imp <- jomoImpute(studentratings, formula=fml, random.L1="full", n.burn=100,
n.iter=10, m=5)
# * Example 2.6: imputation of 'Sex' (categorical) and 'MathAchiev' (continuous),
# predicted by 'ReadAchiev' (random slopes)
# induce some artificial missing data for 'Sex'
studentratings <- within(studentratings,{ Sex[!duplicated(ID)] <- NA
Sex <- as.factor(Sex) })
fml <- Sex + MathAchiev ~ ReadAchiev + (1+ReadAchiev|ID)
imp <- jomoImpute(studentratings, formula=fml, n.burn=100, n.iter=10, m=5)Run the code above in your browser using DataLab