## Not run:
# #############################################################################
# # EXAMPLE 1: Generalized partial credit model
# #############################################################################
#
# data(data.ratings1)
# dat <- data.ratings1
#
# # estimate model
# mod1 <- rm.facets( dat[ , paste0( "k",1:5) ], rater=dat$rater,
# pid=dat$idstud , maxiter=15)
# # extract dataset and item parameters
# data <- mod1$procdata$dat2.NA
# a <- mod1$ipars.dat2$a
# b <- mod1$ipars.dat2$b
# theta0 <- mod1$person$EAP
# # define item response function for item ii
# calc.pcm <- function( theta , a , b , ii ){
# K <- base::ncol(b)
# N <- base::length(theta)
# matrK <- base::matrix( 0:K , nrow=N , ncol=K+1 , byrow=TRUE)
# eta <- a[ii] * theta * matrK - base::matrix( c(0,b[ii,]), nrow=N, ncol=K+1, byrow=TRUE)
# eta <- base::exp(eta)
# probs <- eta / base::rowSums(eta, na.rm=TRUE)
# base::return(probs)
# }
# arg.list <- list("a"=a , "b"=b )
#
# # MLE
# abil1 <- IRT.mle( data, irffct=calc.pcm, theta=theta0, arg.list=arg.list )
# str(abil1)
# # WLE
# abil2 <- IRT.mle( data, irffct=calc.pcm, theta=theta0, arg.list=arg.list, type="WLE")
# str(abil2)
# # MAP with prior distribution N(.2, 1.3)
# abil3 <- IRT.mle( data, irffct=calc.pcm, theta=theta0, arg.list=arg.list,
# type="MAP", mu=.2, sigma=1.3 )
# str(abil3)
#
# #############################################################################
# # EXAMPLE 2: Rasch model
# #############################################################################
#
# data(data.read)
# dat <- data.read
# I <- ncol(dat)
#
# # estimate Rasch model
# mod1 <- rasch.mml2( dat )
# summary(mod1)
#
# # define item response function
# irffct <- function( theta, b , ii){
# eta <- exp( theta - b[ii] )
# probs <- eta / ( 1 + eta )
# probs <- cbind( 1 - probs , probs )
# return(probs)
# }
# # initial person parameters and item parameters
# theta0 <- mod1$person$EAP
# arg.list <- list( "b" = mod1$item$b )
#
# # estimate WLE
# abil <- IRT.mle( data = dat , irffct=irffct , arg.list=arg.list ,
# theta=theta0, type="WLE")
# # compare with wle.rasch function
# theta <- wle.rasch( dat , b= mod1$item$b )
# cbind( abil[,1] , theta$theta , abil[,2] , theta$se.theta )
#
# #############################################################################
# # EXAMPLE 3: Ramsay quotient model
# #############################################################################
#
# data(data.read)
# dat <- data.read
# I <- ncol(dat)
#
# # estimate Ramsay model
# mod1 <- rasch.mml2( dat , irtmodel ="ramsay.qm" )
# summary(mod1)
# # define item response function
# irffct <- function( theta, b , K , ii){
# eta <- exp( theta / b[ii] )
# probs <- eta / ( K[ii] + eta )
# probs <- cbind( 1 - probs , probs )
# return(probs)
# }
# # initial person parameters and item parameters
# theta0 <- exp( mod1$person$EAP )
# arg.list <- list( "b" = mod1$item2$b , "K"=mod1$item2$K )
# # estimate MLE
# res <- IRT.mle( data = dat , irffct=irffct , arg.list=arg.list , theta=theta0 ,
# maxval=20 , maxiter=50)
# ## End(Not run)
Run the code above in your browser using DataLab