# \donttest{
# Fit a Latent Class Analysis model with 5 classes to the sample dataset
result.LCA <- LCA(J15S500, ncls = 5)
# Display the first few rows of student class membership probabilities
head(result.LCA$Students)
# Plot Item Response Profiles (IRP) for items 1-6 in a 2x3 grid
# Shows probability of correct response for each item across classes
plot(result.LCA, type = "IRP", items = 1:6, nc = 2, nr = 3)
# Plot Class Membership Probabilities (CMP) for students 1-9 in a 3x3 grid
# Shows probability distribution of class membership for each student
plot(result.LCA, type = "CMP", students = 1:9, nc = 3, nr = 3)
# Plot Test Response Profile (TRP) showing expected scores for each class
plot(result.LCA, type = "TRP")
# Plot Latent Class Distribution (LCD) showing class sizes
plot(result.LCA, type = "LCD")
# Compare models with different numbers of classes
# (In practice, you might try more class counts)
lca2 <- LCA(J15S500, ncls = 2)
lca3 <- LCA(J15S500, ncls = 3)
lca4 <- LCA(J15S500, ncls = 4)
lca5 <- LCA(J15S500, ncls = 5)
# Compare BIC values to select optimal number of classes
# (Lower BIC indicates better fit)
data.frame(
Classes = 2:5,
BIC = c(
lca2$TestFitIndices$BIC,
lca3$TestFitIndices$BIC,
lca4$TestFitIndices$BIC,
lca5$TestFitIndices$BIC
)
)
# }
Run the code above in your browser using DataLab