# NOT RUN {
#Load irtoys package
require(irtoys)
#Set number of items and number of simulees
n=20
N=250
#Generate item parameters to simulate data
#First column is item discrimination, second column
#is item difficulty, and third column is item guessing
#parameters
ipar <- cbind(rlnorm(n, meanlog = 0, sdlog = .5),
rnorm(n,0,1),
rep(0,n))
#Simulate dichotomous item responses
responses <- as.data.frame(sim(ip=ipar, x=rnorm(N)))
#Estimate item parameters
est.ipar <- est(responses, model = "2PL", engine = "ltm")$est
est.ipar
#If the suspected copier examinee is Examinee 30, and suspected
#source is Examinee 70
CopyDetect1(data=responses,item.par=est.ipar,pair=c(30,70))
#Now, compute these indices for 100 random pairs of examinees
#a small type I error rate study
k=2 # Due to the time constrains in package building, I set
# this to 2. Please set k equals to 100 in your run.
pairs <- as.data.frame(matrix(k,ncol=2))
for(i in 1:k){
d <- sample(1:N,2,replace=FALSE)
pairs[i,1]=d[1]
pairs[i,2]=d[2]
}
pairs$W <- NA
pairs$GBT <- NA
pairs$K <- NA
pairs$K1 <- NA
pairs$K2 <- NA
pairs$S1 <- NA
pairs$S2 <- NA
for(i in 1:k){
x <- CopyDetect1(data=responses,
item.par=est.ipar,
pair=c(pairs[i,1],pairs[i,2]))
pairs[i,]$W=x$W.index$p.value
pairs[i,]$GBT=x$GBT.index$p.value
pairs[i,]$K=x$K.index$k.index
pairs[i,]$K1=x$K.variants$K1.index
pairs[i,]$K2=x$K.variants$K2.index
pairs[i,]$S1=x$K.variants$S1.index
pairs[i,]$S2=x$K.variants$S2.index
}
#Check the false detection rates at alpha level of .05
#(empirical type I error rates)
#We expect to see 5% of the pairs be detected just by chance
length(which(pairs$W<.05))/k
length(which(pairs$GBT<.05))/k
length(which(pairs$K<.05))/k
length(which(pairs$K1<.05))/k
length(which(pairs$K2<.05))/k
length(which(pairs$S1<.05))/k
length(which(pairs$S2<.05))/k
#Now, compute these indices for 5 answer copying pairs
#a tiny empirical power study
#First we will randomly choose a copier examinee
#Second, we will randomly choose a corresponding source examinee
#Third, we will randomly select 10 items (50% copying)
#Finally, we will overwrite the response vector of the source examinee
#on the response vector of the copier examinee
#This mimicks the scenario that the copier examinee looks at the
#source examinee's sheet and copies 10 items in a 20-item test.
copy.pairs <- as.data.frame(matrix(nrow=5,ncol=2))
for(i in 1:5){
d <- sample(1:N,2,replace=FALSE)
copy.pairs[i,1]=d[1] #hypothetical copier examinee
copy.pairs[i,2]=d[2] #hypothetical source examinee
}
new.responses <- responses
for(i in 1:5){ #Simulate answer copying for each answer copying pair
copy.items <- sample(1:n,10,replace=FALSE)
new.responses[copy.pairs[i,1],copy.items]=new.responses[copy.pairs[i,2],copy.items]
}
#Compute indices for pairs on the original response vectors
copy.pairs$W1 <- NA
copy.pairs$GBT1 <- NA
copy.pairs$K_1 <- NA
copy.pairs$K1_1 <- NA
copy.pairs$K2_1 <- NA
copy.pairs$S1_1 <- NA
copy.pairs$S2_1 <- NA
for(i in 1:5){
x <- CopyDetect1(data=responses,
item.par=est.ipar,
pair=c(copy.pairs[i,1],copy.pairs[i,2]))
copy.pairs[i,]$W1=x$W.index$p.value
copy.pairs[i,]$GBT1=x$GBT.index$p.value
copy.pairs[i,]$K_1=x$K.index$k.index
copy.pairs[i,]$K1_1=x$K.variants$K1.index
copy.pairs[i,]$K2_1=x$K.variants$K2.index
copy.pairs[i,]$S1_1=x$K.variants$S1.index
copy.pairs[i,]$S2_1=x$K.variants$S2.index
}
#Compute indices for same pairs on answer copying simulated response vectors
est.ipar2 <- est(new.responses, model = "2PL", engine = "ltm")$est
copy.pairs$W2 <- NA
copy.pairs$GBT2 <- NA
copy.pairs$K_2 <- NA
copy.pairs$K1_2 <- NA
copy.pairs$K2_2 <- NA
copy.pairs$S1_2 <- NA
copy.pairs$S2_2 <- NA
for(i in 1:5){
x <- CopyDetect1(data=new.responses,
item.par=est.ipar2,
pair=c(copy.pairs[i,1],copy.pairs[i,2]))
copy.pairs[i,]$W2=x$W.index$p.value
copy.pairs[i,]$GBT2=x$GBT.index$p.value
copy.pairs[i,]$K_2=x$K.index$k.index
copy.pairs[i,]$K1_2=x$K.variants$K1.index
copy.pairs[i,]$K2_2=x$K.variants$K2.index
copy.pairs[i,]$S1_2=x$K.variants$S1.index
copy.pairs[i,]$S2_2=x$K.variants$S2.index
}
#Let's see what happens!
print(copy.pairs)
# }
Run the code above in your browser using DataLab