## Not run:
#
# ## Rasch or 2pl Model
#
# # Data should be a numeric matrix, with one row per candidate, one column per item
# data(physics)
# # If reading from csv, the following is recommended:
# # physics<-read.csv("physics.csv", header=TRUE, sep=",", na.strings = "-")
# # physics<-physics[complete.cases(physics),]
# # physics<-physics[sample(1:nrow(physics), 200, replace=FALSE),]
# # physics<-as.matrix(physics)
#
# n <- nrow(physics)
# p <- ncol(physics)
#
# # Boundary marks in ascending order
# bnds <- c(9,11,13,15,18,21)
#
# # Labels for boundaries (one more boundary than label)
# lbls <- c("U","E","D","C","B","A","A*")
#
# # Specify bugs file - included in the classify/bugs directory
# # 2 pl model
# mdl <- "tpl.bug"
# # Rasch model
# # mdl <- "rasch.bug"
#
# # Item marks
# Y <- physics
#
# # Mean and standard deviation of delta
# m.delta <- 0.0
# s.delta <- 1.0
#
# # Mean and standard deviation of alpha, comment out for Rasch model
# m.alpha <- 0.0
# s.alpha <- 1.0
#
# # Data set for the 2 pl model
# data <- list("Y", "n", "p", "m.delta", "s.delta", "m.alpha", "s.alpha")
#
# # Parameters to monitor for the 2 pl model
# monitor <- c("delta", "theta", "alpha")
#
# # Rasch model
# # data <- list("Y", "n", "p", "m.delta", "s.delta")
# # monitor <- c("delta", "theta")
#
# # Set to location of bug file
# jags.file <- file.path(getwd(), "R/R-2.15.0/library/classify/bugs" ,mdl)
#
# # JAGS
# # may require set.seed(1234) depending on version of R
# system.time(jagsout <- jags(data=data, inits=NULL, parameters.to.save=monitor,
# model.file=jags.file,
# n.iter=2000, n.thin=10, n.burnin=1000))
#
# sims <- jagsout$BUGSoutput$sims.matrix
#
# # Bugs
# # Change this to your bugs directory
# # bugs.directory = "C:/Program Files/WinBUGS14"
# # system.time(bugsout <- bugs(data=data, inits=NULL, parameters.to.save=monitor,
# # model.file=jags.file,
# # n.iter=2000, n.thin=10, n.burnin=1000))
#
# # sims <- bugsout$sims.matrix
#
# # Estimate conditional score and expected score distributions
# scores <- scores.gpcm.bug(Y,sims,mdl)
# # Plots
# plot(scores)
# # Save plot
# # ggsave("expected.pdf")
# plot(scores,type="cond")
# plot(scores,type="qq",alpha=0.5)
#
# # Estimate accuracy statistics
# accs <- classify.bug(sims,scores,bnds,lbls)
# summary(accs)
# plot(accs)
# plot(accs,type="kappa")
# plot(accs,type="density")
#
# ##############################################
# ##############################################
#
# ## PCM or GPCM models
# # Data should be a numeric matrix, with one row per candidate, one column per item
# data(biology)
# # If reading from csv, the following is recommended:
# # biology<-read.csv("biology.csv", header=TRUE, sep=",", na.strings = "-")
# # biology<-biology[complete.cases(biology),]
# # biology<-biology[sample(1:nrow(biology), 200, replace=FALSE),]
# # biology<-as.matrix(biology)
#
# n <- nrow(biology)
# p <- ncol(biology)
#
# # Boundary marks in ascending order
# bnds <- c(26,30,35,40,45)
#
# # Labels for boundaries (one more boundary than label)
# lbls <- c("U","E","D","C","B","A")
#
# # Specify bugs file - included in the classify/bugs directory
# # GPCM
# mdl <- "gpcm.bug"
# # PCM
# #mdl <- "pcm.bug"
#
# # Bugs polytomous models require polytomous scores as categories
# Y <- biology + 1
# # Specify response categories
# K <- as.numeric(apply(Y,2,max,na.rm = TRUE))
#
# # Mean and standard deviation of alpha and beta parameters
#
# m.beta <- 0.0
# s.beta <- 1.0
#
# # Comment out for PCM
# m.alpha <- 0.0
# s.alpha <- 1.0
#
# # GPCM
# data <- list("Y", "n", "p", "K",
# "m.beta", "s.beta", "m.alpha", "s.alpha")
# monitor <- c("beta", "theta", "alpha")
#
# # PCM
# #data <- list("Y", "n", "p", "K",
# # "m.beta", "s.beta")
# #monitor <- c("beta", "theta")
#
# # Initial values for beta set to 0, matrix padded with NA
# beta <- t(sapply(1:p, function(j) c(rep(NA, K[j]), rep(0.0, max(K) - K[j]))))
# data <- c(data, "beta")
#
# # Change this to bugs file directory
# jags.file <- file.path(getwd(), "R/R-2.15.0/library/classify/bugs" ,mdl)
#
# # Simulations and sampling
# iter <- 2000
# burnin <- 1000
# thin <- 10
#
# ## JAGS
# estimation <- "jags"
# # may require set.seed(1234) depending on version of R
# system.time(jagsout <- jags(data=data, inits=NULL, parameters.to.save=monitor,
# model.file=jags.file,
# n.iter=iter, n.thin=thin, n.burnin=burnin))
# sims <- jagsout$BUGSoutput$sims.matrix
#
#
# ## Bugs
# #estimation <- "bugs"
# # Change this to your bugs directory
# #bugs.directory = "C:/Program Files/WinBUGS14"
# #system.time(bugsout <- jags(data=data, inits=NULL, parameters.to.save=monitor,
# # model.file=jags.file,
# # n.iter=iter, n.thin=thin, n.burnin=burnin))
# #sims <- bugsout$sims.matrix
#
# # Estimate conditional score and expected score distributions
# scores <- scores.gpcm.bug(biology,sims,mdl)
# # Plots
# plot(scores)
# # Save plot
# #ggsave("expected.pdf")
# plot(scores,type="cond")
# plot(scores,type="qq",alpha=0.5)
#
# # Estimate accuracy statistics
# accs <- classify.bug(sims,scores,bnds,lbls)
# summary(accs)
# plot(accs)
# plot(accs,type="kappa")
# plot(accs,type="density")
#
# ## End(Not run)
Run the code above in your browser using DataLab