## Not run:
#
# ### unidimensional scored example with generated items
#
# # create mo from estimated parameters
# set.seed(1234)
# nitems <- 50
# itemnames <- paste0('Item.', 1:nitems)
# a <- matrix(rlnorm(nitems, .2, .3))
# d <- matrix(rnorm(nitems))
# dat <- simdata(a, d, 1000, itemtype = 'dich')
# mod <- mirt(dat, 1)
# coef(mod, simplify=TRUE)
#
# # alternatively, define mo from population values (not run)
# pars <- data.frame(a1=a, d=d)
# mod2 <- generate.mirt_object(pars, itemtype='2PL')
# coef(mod2, simplify=TRUE)
#
# # simple math items
# questions <- answers <- character(nitems)
# choices <- matrix(NA, nitems, 5)
# spacing <- floor(d - min(d)) + 1 #easier items have more variation in the options
#
# for(i in 1:nitems){
# n1 <- sample(1:50, 1)
# n2 <- sample(51:100, 1)
# ans <- n1 + n2
# questions[i] <- paste0(n1, ' + ', n2, ' = ?')
# answers[i] <- as.character(ans)
# ch <- ans + sample(c(-5:-1, 1:5) * spacing[i,], 5)
# ch[sample(1:5, 1)] <- ans
# choices[i, ] <- as.character(ch)
# }
#
# df <- data.frame(Question=questions, Option=choices,
# Type = 'radio', stringsAsFactors = FALSE)
# head(df)
#
# (res <- mirtCAT(df)) #collect response only (no scoring or estimating thetas)
# summary(res)
#
# # include scoring by providing Answer key
# df$Answer <- answers
# (res_seq <- mirtCAT(df, mod)) #sequential scoring
# (res_random <- mirtCAT(df, mod, criteria = 'random')) #random
# (res_MI <- mirtCAT(df, mod, criteria = 'MI', start_item = 'MI')) #adaptive, MI starting item
#
# summary(res_seq)
# summary(res_random)
# summary(res_MI)
#
# #-----------------------------------------
#
# # run locally, random response pattern given Theta
# set.seed(1)
# pat <- generate_pattern(mod, Theta = 0, df=df)
# head(pat)
#
# # seq scoring with character pattern for the entire test (adjust min_items)
# res <- mirtCAT(df, mod, local_pattern=pat, design = list(min_items = 50))
# summary(res)
#
# # same as above, but using special input vector that doesn't require df input
# set.seed(1)
# pat2 <- generate_pattern(mod, Theta = 0)
# head(pat2)
# print(mirtCAT(mo=mod, local_pattern=pat2))
#
# # run CAT, and save results to object called person (start at 10th item)
# person <- mirtCAT(df, mod, item_answers = answers, criteria = 'MI',
# start_item = 10, local_pattern = pat)
# print(person)
# summary(person)
#
# # plot the session
# plot(person) #standard errors
# plot(person, SE=1.96) #95 percent confidence intervals
#
# #-----------------------------------------
#
# ### save response object to temp directory in case session ends early
# wdf <- paste0(getwd(), '/temp_file.rds')
# res <- mirtCAT(df, mod, shinyGUI = list(temp_file = wdf))
#
# # resume test this way if test was stopped early (and temp files were saved)
# res <- mirtCAT(df, mod, shinyGUI = list(temp_file = wdf))
# print(res)
#
# ## End(Not run)
Run the code above in your browser using DataLab