## GENERATION OF VECTORS OF RESPONSE
# NOTE THE USUAL PARAMETRIZATION OF THE ITEM DISCRIMINATION,
# THE VALUE OF THE PERSONNAL FLUCTUATION FIXED AT 0,
# AND THE VALUE OF THE PERSONNAL PSEUDO-GUESSING FIXED AT 0.30.
# IT COULD BE TYPICAL OF PLAGIARISM BEHAVIOR.
nItems <- 40
a <- rep(1.702,nItems); b <- seq(-5,5,length=nItems)
c <- rep(0,nItems); d <- rep(1,nItems)
nSubjects <- 1; rep <- 2
theta <- seq(-1,-1,length=nSubjects)
S <- runif(n=nSubjects,min=0.0,max=0.0)
C <- runif(n=nSubjects,min=0.3,max=0.3)
D <- runif(n=nSubjects,min=0,max=0)
set.seed(seed = 100)
X <- ggrm4pl(n=nItems, rep=rep,
theta=theta, S=S, C=C, D=D,
s=1/a, b=b,c=c,d=d)
## Genreric function m4plPersonParameters to use
## prefered to the more specific one: m4plEstimate and m4plEstimateMore
# ....................................................................
model <- "C"
test1 <- m4plPersonParameters(x=X, b=b, s=1/a, c=c, d=d, m=0, model=model,
prior="uniform", more=FALSE)
test2 <- m4plPersonParameters(x=X, b=b, s=1/a, c=c, d=d, m=0, model=model,
prior="uniform", more=TRUE)
# ....................................................................
## ESTIMATION OF THE PERSONNAL PARAMETERS BY ALL MODELS.
# THE CHOOSEN PRIOR IS UNIFORM WITH m=0.
# ....................................................................
m4plEstimate(x=X, b=b, s=1/a, c=c, d=d, m=0, model= "T", prior="uniform")
m4plEstimate(x=X, b=b, s=1/a, c=c, d=d, m=0, model= "S", prior="uniform")
m4plEstimate(x=X, b=b, s=1/a, c=c, d=d, m=0, model= "C", prior="uniform")
m4plEstimate(x=X, b=b, s=1/a, c=c, d=d, m=0, model= "D", prior="uniform")
m4plEstimate(x=X, b=b, s=1/a, c=c, d=d, m=0, model= "SC", prior="uniform")
m4plEstimate(x=X, b=b, s=1/a, c=c, d=d, m=0, model= "SD", prior="uniform")
m4plEstimate(x=X, b=b, s=1/a, c=c, d=d, m=0, model= "CD", prior="uniform")
m4plEstimate(x=X, b=b, s=1/a, c=c, d=d, m=0, model= "SCD", prior="uniform")
# ....................................................................
## THE SAME ESTIMATION, BUT WITH INFORMATION ABOUT
# THE STANDARD ERROR, THE CORRELATION AND THE LOG LIKELIKOOD
m4plEstimateMore(x=X, b=b, s=1/a, c=c, d=d, m=0, model= "T", prior="uniform")
m4plEstimateMore(x=X, b=b, s=1/a, c=c, d=d, m=0, model= "S", prior="uniform")
m4plEstimateMore(x=X, b=b, s=1/a, c=c, d=d, m=0, model= "C", prior="uniform")
m4plEstimateMore(x=X, b=b, s=1/a, c=c, d=d, m=0, model= "D", prior="uniform")
m4plEstimateMore(x=X, b=b, s=1/a, c=c, d=d, m=0, model= "SC", prior="uniform")
m4plEstimateMore(x=X, b=b, s=1/a, c=c, d=d, m=0, model= "SD", prior="uniform")
m4plEstimateMore(x=X, b=b, s=1/a, c=c, d=d, m=0, model= "CD", prior="uniform")
m4plEstimateMore(x=X, b=b, s=1/a, c=c, d=d, m=0, model= "SCD", prior="uniform")
# ....................................................................
## Same simulation, but with replications
# ....................................................................
rep <- 100
set.seed(seed = 100)
X <- ggrm4pl(n=nItems, rep=rep,
theta=theta, S=S, C=C, D=D,
s=1/a, b=b,c=c,d=d)
## Function used to extract each parameters of the list return by m4plEstimateMore
extract <- function(x,i) x[[i]]
## Usual IRT model integrating only the parameters theta
apply( X, 1, m4plEstimate, b=b, s=1/a, c=c, d=d, m=0, model= "T",
prior="uniform")
tests <- apply(X, 1, m4plEstimateMore, b=b, s=1/a, c=c, d=d, m=0, model= "T",
prior="uniform")
personParameters <- matrix(unlist(lapply(tests,extract,1)),nrow=rep)
personSe <- matrix(unlist(lapply(tests,extract,2)),nrow=rep)
personCor <- matrix(unlist(lapply(tests,extract,3)),nrow=rep)
personLL <- matrix(unlist(lapply(tests,extract,4)),nrow=rep)
results <- data.frame(Parameter=personParameters, Se=personSe,
LL=personLL)
round(c(mean=mean(results, na.rm=TRUE)),2); round(c(se=sd(results, na.rm=TRUE)),2)
## Model integrating the parameters theta and C
# Same response patterns for comparison of estimates
t( apply(X, 1, m4plEstimate, b=b, s=1/a, c=c, d=d, m=0, model= "C",
prior="uniform"))
tests <- apply(X, 1, m4plEstimateMore, b=b, s=1/a, c=c, d=d, m=0, model= "C",
prior="uniform")
personParameters <- t(matrix(unlist(lapply(tests,extract,1)),ncol=rep))
personSe <- t(matrix(unlist(lapply(tests,extract,2)),ncol=rep))
personLL <- t(matrix(unlist(lapply(tests,extract,4)),ncol=rep))
results <- data.frame(Parameter=personParameters, Se=personSe,
LL=personLL)
round(c(mean=mean(results, na.rm=TRUE)),2); round(c(se=sd(results, na.rm=TRUE)),2)
## Average correlation between the person parameters
nParameters <- length(personParameters[1,])
personCor <- unlist(lapply(tests,extract,3))
personCor <- matrix( mean(data.frame(t(matrix(personCor,ncol=rep))), na.rm=TRUE),
ncol=nParameters)
personCor
## Model integrating the parameters theta and C
# Same response patterns for comparison of estimates
t(apply( X,1, m4plEstimate, b=b, s=1/a, c=c, d=d, m=0, model= "SCD",
prior="uniform"))
tests <- apply(X, 1, m4plEstimateMore, b=b, s=1/a, c=c, d=d, m=0, model= "SCD",
prior="uniform")
personParameters <- t(matrix(unlist(lapply(tests,extract,1)),ncol=rep))
personSe <- t(matrix(unlist(lapply(tests,extract,2)),ncol=rep))
personLL <- t(matrix(unlist(lapply(tests,extract,4)),ncol=rep))
results <- data.frame(Parameter=personParameters, Se=personSe,
LL=personLL)
round(c(mean=mean(results, na.rm=TRUE)),2); round(c(se=sd(results, na.rm=TRUE)),2)
## Average correlation between the person parameters
nParameters <- length(personParameters[1,])
personCor <- unlist(lapply(tests,extract,3))
personCor <- matrix( mean(data.frame(t(matrix(personCor,ncol=rep))), na.rm=TRUE),
ncol=nParameters)
personCor
# ....................................................................
Run the code above in your browser using DataLab