#############################################################################
# EXAMPLE 1: Reading data
#############################################################################
data( data.read )
dat <- data.read
#******
# latent class models
# latent class model with 1 class
mod1 <- rasch.mirtlc( dat , Nclasses = 1 )
summary(mod1)
# latent class model with 2 classes
mod2 <- rasch.mirtlc( dat , Nclasses = 2 )
summary(mod2)
# latent class model with 3 classes
mod3 <- rasch.mirtlc( dat , Nclasses = 3 , seed = - 30)
summary(mod3)
# latent class model with 4 classes and
# 3 starts with different seeds
mod4 <- rasch.mirtlc( dat , Nclasses = 4 ,seed= -30 , nstarts=3 )
# display different solutions
sort(mod1$devL)
summary(mod4)
# latent class multiple group model
# define group identifier
group <- rep( 1 , nrow(dat))
group[ 1:150 ] <- 2
mod5 <- rasch.mirtlc( dat , Nclasses = 3 , group = group )
summary(mod5)
#*************
# Unidimensional IRT models with ordered trait
# 1PL model with 3 classes
mod11 <- rasch.mirtlc( dat , Nclasses = 3 , modeltype="MLC1" , mmliter=30)
summary(mod11)
# 1PL model with 11 classes
mod12 <- rasch.mirtlc( dat , Nclasses = 11 ,modeltype="MLC1", mmliter=30)
summary(mod12)
# 1PL model with 11 classes and fixed specified theta values
mod13 <- rasch.mirtlc( dat , modeltype="MLC1" ,
theta.k = seq( -4 , 4 , len=11 ) , mmliter=100)
summary(mod13)
# 1PL model with fixed theta values and normal distribution
mod14 <- rasch.mirtlc( dat , modeltype="MLC1" , mmliter=30 ,
theta.k = seq( -4 , 4 , len=11 ) , distribution.trait="normal")
summary(mod14)
# 1PL model with a smoothed trait distribution (up to 3 moments)
mod15 <- rasch.mirtlc( dat , modeltype="MLC1" , mmliter=30 ,
theta.k = seq( -4, 4 , len=11 ) , distribution.trait="smooth3")
summary(mod15)
# 2PL with 3 classes
mod16 <- rasch.mirtlc( dat , Nclasses=3 , modeltype="MLC2" , mmliter=30 )
summary(mod16)
# 2PL with fixed theta and smoothed distribution
mod17 <- rasch.mirtlc( dat, theta.k=seq(-4,4,len=12) , mmliter=30 ,
modeltype="MLC2" , distribution.trait="smooth4" )
summary(mod17)
# 1PL multiple group model with 8 classes
# define group identifier
group <- rep( 1 , nrow(dat))
group[ 1:150 ] <- 2
mod21 <- rasch.mirtlc( dat , Nclasses = 8 , modeltype="MLC1" , group=group )
summary(mod21)
#***************
# multidimensional latent class IRT models
# define vector of dimensions
dimensions <- rep( 1:3 , each = 4 )
# 3-dimensional model with 8 classes and seed 145
mod31 <- rasch.mirtlc( dat , Nclasses = 8 , mmliter=30 ,
modeltype="MLC1" , seed = 145 , dimensions = dimensions )
summary(mod31)
# try the model above with different starting values
mod31s <- rasch.mirtlc( dat , Nclasses = 8 ,
modeltype="MLC1" , seed = -30 , nstarts=30 , dimensions = dimensions )
summary(mod31s)
# estimation with fixed theta vectors
# => 4^3 = 216 classes
theta.k <- seq(-4 , 4 , len=6 )
theta.k <- as.matrix( expand.grid( theta.k , theta.k , theta.k ) )
mod32 <- rasch.mirtlc( dat , dimensions=dimensions ,
theta.k= theta.k , modeltype="MLC1" )
summary(mod32)
# 3-dimensional 2PL model
mod33 <- rasch.mirtlc( dat , dimensions=dimensions ,
theta.k= theta.k , modeltype="MLC2" )
summary(mod33)
#############################################################################
# SIMLUATED EXAMPLE 2: Skew trait distribution
#############################################################################
set.seed(789)
N <- 1000 # number of persons
I <- 20 # number of items
theta <- sqrt( exp( rnorm( N ) ) )
theta <- theta - mean(theta )
# calculate skewness of theta distribution
mean( theta^3 ) / sd(theta)^3
# simulate item responses
dat <- sim.raschtype( theta , b=seq(-2,2,len=I ) )
# normal distribution
mod1 <- rasch.mirtlc( dat , theta.k=seq(-4,4,len=15) , modeltype="MLC1",
distribution.trait="normal" , mmliter=30)
# allow for skew distribution with smoothed distribution
mod2 <- rasch.mirtlc( dat , theta.k=seq(-4,4,len=15) , modeltype="MLC1",
distribution.trait="smooth3" , mmliter=30)
# nonparametric distribution
mod3 <- rasch.mirtlc( dat , theta.k=seq(-4,4,len=15) , modeltype="MLC1",
mmliter=30)
summary(mod1)
summary(mod2)
summary(mod3)
Run the code above in your browser using DataLab