if (FALSE) {
#############################################################################
# EXAMPLE 1: CCT data, Janssen and Geiser (2010, LID)
# Latent class analysis based on data.janssen
#############################################################################
data(data.janssen)
dat <- data.janssen
colnames(dat)
## [1] "PIS1" "PIS3" "PIS4" "PIS5" "SCR6" "SCR9" "SCR10" "SCR17"
#*********************************************************************
#*** Model 1: Latent class analysis with two classes
tammodel <- "
ANALYSIS:
TYPE=LCA;
NCLASSES(2);
NSTARTS(10,20);
LAVAAN MODEL:
# missing item numbers (e.g. PIS2) are ignored in the model
F=~ PIS1__PIS5 + SCR6__SCR17
"
mod3 <- TAM::tamaan( tammodel, resp=dat )
summary(mod3)
# extract item response functions
imod2 <- IRT.irfprob(mod3)[,2,]
# plot class specific probabilities
ncl <- 2
matplot( imod2, type="o", pch=1:ncl, xlab="Item", ylab="Probability" )
legend( 1, .3, paste0("Class",1:ncl), lty=1:ncl, col=1:ncl, pch=1:ncl )
#*********************************************************************
#*** Model 2: Latent class analysis with three classes
tammodel <- "
ANALYSIS:
TYPE=LCA;
NCLASSES(3);
NSTARTS(10,20);
LAVAAN MODEL:
F=~ PIS1__PIS5 + SCR6__SCR17
"
mod3 <- TAM::tamaan( tammodel, resp=dat )
summary(mod3)
# extract item response functions
imod2 <- IRT.irfprob(mod3)[,2,]
# plot class specific probabilities
ncl <- 3
matplot( imod2, type="o", pch=1:ncl, xlab="Item", ylab="Probability" )
legend( 1, .3, paste0("Class",1:ncl), lty=1:ncl, col=1:ncl, pch=1:ncl )
# compare models
AIC(mod1); AIC(mod2)
}
Run the code above in your browser using DataLab