# standard latent class
pap.lca1 <- randomLCA(pap[, 1:10], freq = pap$Freq, nclass = 1, cores = 1)
pap.lca2 <- randomLCA(pap[, 1:10], freq = pap$Freq, nclass = 2, cores = 1)
# \donttest{
# standard latent class
pap.lca3 <- randomLCA(pap[, 1:10], freq = pap$Freq, nclass = 3, cores = 1)
pap.lca4 <- randomLCA(pap[, 1:10], freq = pap$Freq, nclass = 4, cores = 1)
pap.lca5 <- randomLCA(pap[, 1:10], freq = pap$Freq, nclass = 5, cores = 1)
# repeat with random effect with constant loading
# once BIC increases fitting further models is unnecessary
pap.lca1random <- randomLCA(pap[, 1:10],
freq = pap$Freq, nclass = 1, random = TRUE, cores = 1)
pap.lca2random <- randomLCA(pap[, 1:10],
freq = pap$Freq, nclass = 2, random = TRUE, cores = 1)
pap.lca3random <- randomLCA(pap[, 1:10],
freq = pap$Freq, nclass = 3, random = TRUE, cores = 1)
# can also repeat fits without constant loading to give mixture of IRT models
pap.lca1random2 <- randomLCA(pap[, 1:10],
freq = pap$Freq, nclass = 1, random = TRUE, constload = FALSE, cores = 1)
pap.lca2random2 <- randomLCA(pap[, 1:10],
freq = pap$Freq, nclass = 2, random = TRUE, constload = FALSE, cores = 1)
pap.lca3random2 <- randomLCA(pap[, 1:10],
freq = pap$Freq, nclass = 3, random = TRUE, constload = FALSE, cores = 1)
# produce table of BIC values
# shows 4 class best of standard latent class
# but 2 class latent class with constant loading has better BIC
pap.bic <- data.frame(bic = c(BIC(pap.lca1), BIC(pap.lca2), BIC(pap.lca3),
BIC(pap.lca4), BIC(pap.lca5)), bic2 = c(BIC(pap.lca1random),
BIC(pap.lca2random), BIC(pap.lca3random), NA, NA), bic3 = c(BIC(pap.lca1random2),
BIC(pap.lca2random2), BIC(pap.lca3random2), NA, NA))
print(pap.bic)
# plot 4 class standard
plot(pap.lca4, type = "b")
# plot 2 class standard
plot(pap.lca2random, type = "b")
# }
Run the code above in your browser using DataLab