#############################################################################
# EXAMPLE 1: Dichotomous data sim.rasch
#############################################################################
data(sim.rasch)
# estimate Rasch model
mod1 <- tam.mml(resp=sim.rasch)
# item fit
fit1 <- tam.fit( mod1 )
summary(fit1)
## > summary(fit1)
## parameter Outfit Outfit_t Outfit_p Infit Infit_t Infit_p
## 1 I1 0.966 -0.409 0.171 0.996 -0.087 0.233
## 2 I2 1.044 0.599 0.137 1.029 0.798 0.106
## 3 I3 1.022 0.330 0.185 1.012 0.366 0.179
## 4 I4 1.047 0.720 0.118 1.054 1.650 0.025
#--------
# infit and oufit based on estimated WLEs
library(sirt)
# estimate WLE
wle <- tam.wle(mod1)
# extract item parameters
b1 <- - mod1$AXsi[ , -1 ]
# assess item fit and person fit
fit1a <- sirt::pcm.fit(b=b1, theta=wle$theta , sim.rasch )
fit1a$item # item fit statistic
fit1a$person # person fit statistic
#############################################################################
# EXAMPLE 2: Partial credit model data.gpcm
#############################################################################
data( data.gpcm )
dat <- data.gpcm
# estimate partial credit model in ConQuest parametrization 'item+item*step'
mod2 <- tam.mml( resp=dat , irtmodel="PCM2" )
summary(mod2)
# estimate item fit
fit2 <- tam.fit(mod2)
summary(fit2)
# => The first three rows of the data frame correspond to the fit statistics
# of first three items Comfort, Work and Benefit.
#--------
# infit and oufit based on estimated WLEs
# compute WLEs
wle <- tam.wle(mod2)
# extract item parameters
b1 <- - mod2$AXsi[ , -1 ]
# assess fit
fit1a <- sirt::pcm.fit(b=b1 , theta=wle$theta , dat)
fit1a$item
#############################################################################
# SIMULATED EXAMPLE 3: Fit statistic testing for local independence
#############################################################################
#generate data with local DEPENDENCE and User-defined fit statistics
set.seed(4888)
I <- 40 # 40 items
N <- 1000 # 1000 persons
delta <- seq(-2,2, len=I)
theta <- rnorm(N, 0, 1)
# simulate data
prob <- plogis(outer(theta, delta, "-"))
rand <- matrix(runif(N*I), nrow=N, ncol=I)
resp <- 1*(rand < prob)
colnames(resp) <- paste("I" , 1:I, sep="")
#Introduce some local dependence
for (item in c(10, 20, 30)){
# 20 #are made equal to the previous item
row <- round(runif(0.2*N)*N + 0.5)
resp[row, item+1] <- resp[row, item]
}
#run TAM
mod1 <- tam(resp)
#User-defined fit design matrix
F <- array(0, dim=c(dim(mod1$A)[1], dim(mod1$A)[2], 6))
F[,,1] <- mod1$A[,,10] + mod1$A[,,11]
F[,,2] <- mod1$A[,,12] + mod1$A[,,13]
F[,,3] <- mod1$A[,,20] + mod1$A[,,21]
F[,,4] <- mod1$A[,,22] + mod1$A[,,23]
F[,,5] <- mod1$A[,,30] + mod1$A[,,31]
F[,,6] <- mod1$A[,,32] + mod1$A[,,33]
fit <- tam.fit(mod1, FitMatrix=F)
summary(fit)
#############################################################################
# SIMULATED EXAMPLE 4: Fit statistic testing for items with differing slopes
#############################################################################
#*** simulate data
library(sirt)
set.seed(9875)
N <- 2000
I <- 20
b <- sample( seq( -2 , 2 , length=I ) )
a <- rep( 1, I )
# create some misfitting items
a[c(1,3)] <- c(.5 , 1.5 )
# simulate data
dat <- sirt::sim.raschtype( rnorm(N) , b=b , fixed.a=a )
#*** estimate Rasch model
mod1 <- tam.mml(resp=dat)
#*** assess item fit by infit and outfit statistic
fit1 <- tam.fit( mod1 )$itemfit
round( cbind( "b"=mod1$item$AXsi_.Cat1 , fit1$itemfit[,-1] )[1:7,], 3 )
#*** compute item fit statistic in mirt package
library(mirt)
library(sirt)
mod1c <- mirt::mirt( dat , model=1 , itemtype="Rasch" , verbose=TRUE)
print(mod1c) # model summary
sirt::mirt.wrapper.coef(mod1c) # estimated parameters
fit1c <- mirt::itemfit(mod1c , method="EAP") # model fit in mirt package
# compare results of TAM and mirt
dfr <- cbind( "TAM"=fit1 , "mirt"=fit1c[,-c(1:2)] )
# S-X2 item fit statistic (see also the output from mirt)
library(CDM)
sx2mod1 <- CDM::itemfit.sx2( mod1 )
summary(sx2mod1)
# compare results of CDM and mirt
sx2comp <- cbind( sx2mod1$itemfit.stat[ , c("S-X2" , "p") ] ,
dfr[ , c("mirt.S_X2" , "mirt.p.S_X2") ] )
round( sx2comp , 3 )
Run the code above in your browser using DataLab