#############################################################################
# EXAMPLE 1: Dataset Liking for Science
#############################################################################
data(data.liking.science)
dat <- data.liking.science
# estimate partial credit model using 10 Jackknife units
mod1 <- rasch.evm.pcm( dat , jackunits=10 )
summary(mod1)
# compare results with TAM
library(TAM)
mod2 <- TAM::tam.mml( dat )
r1 <- mod2$xsi$xsi
r1 <- r1 - mean(r1)
# item parameters are similar
dfr <- data.frame( "b_TAM"=r1 , mod1$item[,c( "est","est_jack") ] )
round( dfr , 3 )
## b_TAM est est_jack
## 1 -2.496 -2.599 -2.511
## 2 0.687 0.824 1.030
## 3 -0.871 -0.975 -0.943
## 4 -0.360 -0.320 -0.131
## 5 -0.833 -0.970 -0.856
## 6 1.298 1.617 1.444
## 7 0.476 0.465 0.646
## 8 2.808 3.194 3.439
## 9 1.611 1.460 1.433
## 10 2.396 1.230 1.095
## [...]
# partial credit model in eRm package
library(eRm)
mod3 <- eRm::PCM(X=dat)
summary(mod3)
eRm::plotINFO(mod3) # plot item and test information
eRm::plotICC(mod3) # plot ICCs
eRm::plotPImap(mod3) # plot person-item maps
#############################################################################
# EXAMPLE 2: Garner and Engelhard (2002) toy example dichotomous data
#############################################################################
dat <- scan()
1 0 1 1 1 1 0 0 1 0 0 0 0 1 1 1 1 1 1 0
1 1 0 1 1 1 1 1 1 0 1 0 1 1 1 1 1 1 0 0
dat <- matrix( dat , 10 , 4 , byrow=TRUE)
colnames(dat) <- paste0("I" , 1:4 )
# estimate Rasch model with no jackknifing
mod1 <- rasch.evm.pcm( dat , jackunits=0 )
# paired comparison matrix
mod1$B
## I1_Cat1 I2_Cat1 I3_Cat1 I4_Cat1
## I1_Cat1 0 3 4 5
## I2_Cat1 1 0 3 3
## I3_Cat1 1 2 0 2
## I4_Cat1 1 1 1 0
#############################################################################
# EXAMPLE 3: Garner and Engelhard (2002) toy example polytomous data
#############################################################################
dat <- scan()
2 2 1 1 1 2 1 2 0 0 1 0 0 0 0 0 1 1 2 0 1 2 2 1 1
2 2 0 2 1 2 2 1 1 0 1 0 1 0 0 2 1 2 2 2 2 1 0 0 1
dat <- matrix( dat , 10 , 5 , byrow=TRUE)
colnames(dat) <- paste0("I" , 1:5 )
# estimate partial credit model with no jackknifing
mod1 <- rasch.evm.pcm( dat , jackunits=0 , powB=3 )
# paired comparison matrix
mod1$B
## I1_Cat1 I1_Cat2 I2_Cat1 I2_Cat2 I3_Cat1 I3_Cat2 I4_Cat1 I4_Cat2 I5_Cat1 I5_Cat2
## I1_Cat1 0 0 2 0 1 1 2 1 2 1
## I1_Cat2 0 0 0 3 2 2 2 2 2 3
## I2_Cat1 1 0 0 0 1 1 2 0 2 1
## I2_Cat2 0 1 0 0 1 2 0 3 1 3
## I3_Cat1 1 1 1 1 0 0 1 2 3 1
## I3_Cat2 0 1 0 2 0 0 1 1 1 1
## I4_Cat1 0 1 0 0 0 2 0 0 1 2
## I4_Cat2 1 0 0 2 1 1 0 0 1 1
## I5_Cat1 0 1 0 1 2 1 1 2 0 0
## I5_Cat2 0 0 0 1 0 0 0 0 0 0
#############################################################################
# EXAMPLE 4: Partial credit model for dataset data.mg from CDM package
#############################################################################
library(CDM)
data(data.mg,package="CDM")
dat <- data.mg[ , paste0("I",1:11) ]
#*** Model 1: estimate partial credit model
mod1 <- rasch.evm.pcm( dat )
# item parameters
round( mod1$b , 3 )
## Cat1 Cat2 Cat3
## I1 -1.537 NA NA
## I2 -2.360 NA NA
## I3 -0.574 NA NA
## I4 -0.971 -2.086 NA
## I5 -0.104 0.201 NA
## I6 0.470 0.806 NA
## I7 -1.027 0.756 1.969
## I8 0.897 NA NA
## I9 0.766 NA NA
## I10 0.069 NA NA
## I11 -1.122 1.159 2.689
#*** Model 2: estimate PCM with pairwise package
library(pairwise)
mod2 <- pairwise::pair(daten=dat)
summary(mod2)
plot(mod2)
# compute standard errors
semod2 <- pairwise::pairSE(daten=dat, nsample = 20)
semod2
#############################################################################
# EXAMPLE 5: Differential item functioning for dataset data.mg
#############################################################################
library(CDM)
data(data.mg,package="CDM")
dat <- data.mg[ data.mg$group %in% c(2,3,11) , ]
# define items
items <- paste0("I",1:11)
# estimate model
mod1 <- rasch.evm.pcm( dat[,items] , weights= dat$weight , group= dat$group )
summary(mod1)
#############################################################################
# SIMULATED EXAMPLE 6: Differential item functioning for Rasch model
#############################################################################
# simulate some data
set.seed(9776)
N <- 1000 # number of persons
I <- 10 # number of items
# simulate data for first group
b <- seq(-1.5,1.5,len=I)
dat1 <- sim.raschtype( rnorm(N) , b )
# simulate data for second group
b1 <- b
b1[4] <- b1[4] + .5 # introduce DIF for fourth item
dat2 <- sim.raschtype( rnorm(N,mean=.3) , b1 )
dat <- rbind(dat1 , dat2 )
group <- rep( 1:2 , each=N )
# estimate model
mod1 <- rasch.evm.pcm( dat , group= group )
summary(mod1)
Run the code above in your browser using DataLab