# NOT RUN {
library(lavaan)
#############################################################################
# EXAMPLE 1: Two-dimensional confirmatory factor analysis data.Students
#############################################################################
data(data.Students, package="CDM")
# select variables
vars <- scan(nlines=1, what="character")
sc1 sc2 sc3 sc4 mj1 mj2 mj3 mj4
dat <- data.Students[, vars]
# define Q-matrix
Q <- matrix( 0, nrow=8, ncol=2 )
Q[1:4,1] <- Q[5:8,2] <- 1
#*** Model 1: Two-dimensional 2PL model
mod1 <- TAM::tam.mml.2pl( dat, Q=Q, control=list( nodes=seq(-4,4,len=12) ) )
summary(mod1)
# linear approximation CFA
cfa1 <- TAM::IRT.linearCFA(mod1)
summary(cfa1)
# linear CFA in lavaan package
lavmodel <- "
sc=~ sc1+sc2+sc3+sc4
mj=~ mj1+mj2+mj3+mj4
sc1 ~ 1
sc ~~ mj
"
mod1b <- lavaan::sem( lavmodel, data=dat, missing="fiml", std.lv=TRUE)
summary(mod1b, standardized=TRUE, fit.measures=TRUE )
#############################################################################
# EXAMPLE 2: Unidimensional confirmatory factor analysis data.Students
#############################################################################
data(data.Students, package="CDM")
# select variables
vars <- scan(nlines=1, what="character")
sc1 sc2 sc3 sc4
dat <- data.Students[, vars]
#*** Model 1: 2PL model
mod1 <- TAM::tam.mml.2pl( dat )
summary(mod1)
# linear approximation CFA
cfa1 <- TAM::IRT.linearCFA(mod1)
summary(cfa1)
# linear CFA
lavmodel <- "
sc=~ sc1+sc2+sc3+sc4
"
mod1b <- lavaan::sem( lavmodel, data=dat, missing="fiml", std.lv=TRUE)
summary(mod1b, standardized=TRUE, fit.measures=TRUE )
# }
Run the code above in your browser using DataLab