if (FALSE) {
#############################################################################
# EXAMPLE 1: Dataset G308 from Schroeders et al. (2014)
#############################################################################
data(data.g308)
dat <- data.g308
library(TAM)
library(sirt)
# define testlets
testlet <- c(1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 4, 4, 4, 4, 4, 5, 5, 6, 6, 6)
#****************************************
#*** Model 1: Rasch model
mod1 <- TAM::tam.mml(resp=dat, control=list(maxiter=300, snodes=1500))
summary(mod1)
#****************************************
#*** Model 2: Rasch testlet model
# testlets are dimensions, assign items to Q-matrix
TT <- length(unique(testlet))
Q <- matrix(0, nrow=ncol(dat), ncol=TT + 1)
Q[,1] <- 1 # First dimension constitutes g-factor
for (tt in 1:TT){Q[testlet==tt, tt+1] <- 1}
# In a testlet model, all dimensions are uncorrelated among
# each other, that is, all pairwise correlations are set to 0,
# which can be accomplished with the "variance.fixed" command
variance.fixed <- cbind(t( utils::combn(TT+1,2)), 0)
mod2 <- TAM::tam.mml(resp=dat, Q=Q, variance.fixed=variance.fixed,
control=list(snodes=1500, maxiter=300))
summary(mod2)
#****************************************
#*** Model 3: Partial credit model
scores <- list()
testlet.names <- NULL
dat.pcm <- NULL
for (tt in 1:max(testlet) ){
scores[[tt]] <- rowSums (dat[, testlet==tt, drop=FALSE])
dat.pcm <- c(dat.pcm, list(c(scores[[tt]])))
testlet.names <- append(testlet.names, paste0("testlet",tt) )
}
dat.pcm <- as.data.frame(dat.pcm)
colnames(dat.pcm) <- testlet.names
mod3 <- TAM::tam.mml(resp=dat.pcm, control=list(snodes=1500, maxiter=300) )
summary(mod3)
#****************************************
#*** Model 4: Copula model
mod4 <- sirt::rasch.copula2 (dat=dat, itemcluster=testlet)
summary(mod4)
}
Run the code above in your browser using DataLab