#############################################################################
# EXAMPLE 1: Dichotomous data
#############################################################################
data(sim.rasch)
resp <- sim.rasch[1:700 , seq( 1 , 40 , len=10) ] # subsample
# estimate the Rasch model with JML (function 'tam.jml')
mod1a <- tam.jml(resp=resp)
summary(mod1a)
itemfit <- tam.fit(mod1a)$fit.item
# the same model but using function 'tam.jml2'
mod1b <- tam.jml2(resp=resp)
summary(mod1b)
itemfit <- tam.fit(mod1b)$fit.item
# compare results with Rasch model estimated by MML
mod1c <- tam.mml(resp=resp )
# plot estimated parameters
plot( mod1b$xsi , mod1c$xsi$xsi , pch=16 ,
xlab= expression( paste( xi[i] , "(JML)" )) ,
ylab= expression( paste( xi[i] , "(MML)" )) ,
main="Item Parameter Estimate Comparison")
lines( c(-5,5) , c(-5,5) , col="gray" )
# Now, the adjustment pf .05 instead of the default .3 is used.
mod1d <- tam.jml2(resp=resp , adj=.05)
# compare item parameters
round( rbind( mod1b$xsi , mod1d$xsi ) , 3 )
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
## [1,] -2.076 -1.743 -1.217 -0.733 -0.338 0.147 0.593 1.158 1.570 2.091
## [2,] -2.105 -1.766 -1.233 -0.746 -0.349 0.139 0.587 1.156 1.574 2.108
# person parameters for persons with a score 0, 5 and 10
pers1 <- data.frame( "score_adj0.3"= mod1b$PersonScore , "theta_adj0.3"= mod1b$theta ,
"score_adj0.05"= mod1d$PersonScore , "theta_adj0.05"= mod1d$theta )
round( pers1[ c(698, 683, 608) , ] ,3 )
## score_adj0.3 theta_adj0.3 score_adj0.05 theta_adj0.05
## 698 0.3 -4.404 0.05 -6.283
## 683 5.0 -0.070 5.00 -0.081
## 608 9.7 4.315 9.95 6.179
#*** Models in which some item parameters are fixed
xsi.fixed <- cbind( c(1,3,9,10) , c(-2 , -1.2 , 1.6 , 2 ) )
mod1e <- tam.jml2( resp=resp , xsi.fixed = xsi.fixed )
summary(mod1e)
# the same fixing in tam.jml
mod1f <- tam.jml( resp=resp , xsi.fixed = xsi.fixed )
summary(mod1f)
#*** Model in which also some person parameters theta are fixed
# fix theta parameters of persons 2, 3, 4 and 33 to values -2.9, ...
theta.fixed <- cbind( c(2,3,4,33) , c( -2.9 , 4 , -2.9 , -2.9 ) )
mod1g <- tam.jml( resp=resp , xsi.fixed = xsi.fixed , theta.fixed=theta.fixed )
# look at estimated results
ind.person <- c( 1:5 , 30:33 )
cbind( mod1g$WLE , mod1g$errorWLE )[ind.person,]
#############################################################################
# EXAMPLE 2: Partial credit model
#############################################################################
data(data.gpcm)
# the same model but using function 'tam.jml2'
mod2 <- tam.jml2(resp=data.gpcm)
mod2$xsi # extract item parameters
summary(mod2)
tam.fit(mod2) # item and person infit/outfit statistic
#############################################################################
# EXAMPLE 3: Facet model estimation using joint maximum likelihood
# data.ex10; see also Example 10 in tam.mml
#############################################################################
data(data.ex10)
dat <- data.ex10
## > head(dat)
## pid rater I0001 I0002 I0003 I0004 I0005
## 1 1 0 1 1 0 0
## 1 2 1 1 1 1 0
## 1 3 1 1 1 0 1
## 2 2 1 1 1 0 1
## 2 3 1 1 0 1 1
facets <- dat[ , "rater" , drop=FALSE ] # define facet (rater)
pid <- dat$pid # define person identifier (a person occurs multiple times)
resp <- dat[ , -c(1:2) ] # item response data
formulaA <- ~ item * rater # formula
# use MML function only to restructure data and input obtained design matrices
# and processed response data to tam.jml (-> therefore use only 2 iterations)
mod3a <- tam.mml.mfr( resp=resp , facets=facets , formulaA = formulaA ,
pid=dat$pid , control=list(maxiter=2) )
# use modified response data mod3a$resp and design matrix mod3a$A
resp1 <- mod3a$resp
# JML with 'tam.jml'
mod3b <- tam.jml( resp=resp1 , A=mod3a$A , control=list(maxiter=200) )
# 'tam.jml2'
mod3c <- tam.jml2( resp=resp1 , A=mod3a$A , control=list(maxiter=200) )
#############################################################################
# EXAMPLE 4: Multi faceted model with some anchored item and person parameters
#############################################################################
data(data.exJ03)
resp <- data.exJ03$resp
X <- data.exJ03$X
#*** (0) preprocess data with tam.mml.facets
mod0 <- tam.mml.mfr( resp=resp , facets = X , pid = X$rater ,
formulaA = ~ leader + item + step ,
control=list(maxiter=2) )
summary(mod0)
#*** (1) estimation with tam.jml (no parameter fixings)
# extract processed data and design matrix from tam.mml.mfr
resp1 <- mod0$resp
A1 <- mod0$A
# estimate model with tam.jml
mod1 <- tam.jml( resp=resp1 , A=A1 , control=list( Msteps=4 , maxiter=100 ) )
summary(mod1)
#*** (2) fix some parameters (persons and items)
# look at indices in mod1$xsi
mod1$xsi
# fix step parameters
xsi.index1 <- cbind( 21:25 , c( -2.44 , 0.01 , -0.15 , 0.01 , 1.55 ) )
# fix some item parameters of items 1,2,3,6 and 13
xsi.index2 <- cbind( c(1,2,3,6,13) , c(-2,-1,-1,-1.32 , -1 ) )
xsi.index <- rbind( xsi.index1 , xsi.index2 )
# fix some theta parameters of persons 1, 15 and 20
theta.fixed <- cbind( c(1,15,20) , c(0.4 , 1 , 0 ) )
# estimate model
mod2 <- tam.jml( resp=resp1 , A=A1 , xsi.fixed=xsi.fixed , theta.fixed=theta.fixed ,
control=list( Msteps=4 , maxiter=100 ) )
summary(mod2)
cbind( mod2$WLE , mod2$errorWLE )
Run the code above in your browser using DataLab