Customize GUI

This demonstrates how to modify various elements in the shiny GUI.

library('mirtCAT')
options(stringsAsFactors = FALSE)

# define population IRT parameters
set.seed(1234)
nitems <- 120
itemnames <- paste0("Item.", 1:nitems)
a <- matrix(c(rlnorm(nitems/2, 0.2, 0.3), rnorm(nitems/4, 0, 0.3), numeric(nitems/2),
    rnorm(nitems/4, 0, 0.3), rlnorm(nitems/2, 0.2, 0.3)), nitems)
d <- matrix(rnorm(nitems))
pars <- data.frame(a, d)
colnames(pars) <- c("a1", "a2", "d")
trait_cov <- matrix(c(1, 0.5, 0.5, 1), 2, 2)

# create mirt_object
mod <- generate.mirt_object(pars, itemtype = "2PL", latent_covariance = trait_cov)

# math items definitions addition for one factor and multiplication for the other
questions <- answers <- character(nitems)
options <- matrix("", nitems, 5)
spacing <- floor(d - min(d)) + 1  #easier items have more variation

for (i in 1:nitems) {
    if (i < 31) {
        # addition
        n1 <- sample(1:100, 1)
        n2 <- sample(101:200, 1)
        ans <- n1 + n2
        questions[i] <- paste0(n1, " + ", n2, " = ?")
    } else if (i < 61) {
        # addition and multiplication
        n1 <- sample(1:50, 1)
        n2 <- sample(51:100, 1)
        m1 <- sample(1:10, 1)
        m2 <- sample(1:10, 1)
        ans <- n1 + n2 + m1 * m2
        questions[i] <- paste0(n1, " + ", n2, " + ", m1, " * ", m2, " = ?")
    } else if (i < 91) {
        # multiplication and addition
        n1 <- sample(1:10, 1)
        n2 <- sample(1:10, 1)
        m1 <- sample(1:25, 1)
        m2 <- sample(1:25, 1)
        ans <- n1 + n2 + m1 * m2
        questions[i] <- paste0(m1, " * ", m2, " + ", n1, " + ", n2, " = ?")
    } else {
        # multiplication
        m1 <- sample(1:50, 1)
        m2 <- sample(1:50, 1)
        ans <- n1 + n2 + m1 * m2
        questions[i] <- paste0(m1, " * ", m2, " = ?")
    }
    answers[i] <- as.character(ans)
    ch <- ans + sample(c(-5:-1, 1:5) * spacing[i, ], 5)
    ch[sample(1:5, 1)] <- ans
    options[i, ] <- as.character(ch)
}

# load list of items and their answers
df <- data.frame(Question = questions, Option = options, Answer = answers, Type = "radio")

The following adds two .png files to the GUI as item stems for more customized item stimuli.

# download the stems
download.file("https://raw.githubusercontent.com/philchalmers/mirtCAT/master/tests/GUI-tests/Math-stem.html", 
              destfile = "Math-stem.html", method = "curl")

download.file("https://raw.githubusercontent.com/philchalmers/mirtCAT/master/tests/GUI-tests/Table-stem.html", 
              destfile = "Table-stem.html", method = "curl")

# construct new stems inputs
type <- c("radio_inline", "select")
questions <- c("", "Which equation in the above table is INCORRECT?")
options <- rbind(c("1236", "1238", "1240", "1242", "1244"), c("A)", "B)", "C)", "D)",
    "E)"))
answers <- c("1236", "D)")

#stem paths can be relative or absolute (relative here, in the save working directory)
stem_locations <- c("Math-stem.html", "Table-stem.html")
twoitems <- data.frame(Question = questions, Option = options, Answer = answers,
    Stem = stem_locations, Type = type, stringsAsFactors = FALSE)

library(plyr)
df2 <- rbind.fill(twoitems, df)
results <- mirtCAT(df = df2, design = list(max_items = 2))

Finally, the following modifies various elements, such as the minimum and maximum number of items to administer, the amount of item exposure to sample from, and performs a Pre-CAT stage to collect response data prior to the CAT session.

As well, several GUI elements are modified, such as the title, author names, the first page, and the last page.

design_list <- list(max_items = 10, min_items = 5, min_SEM = 0.4, exposure = rep(3, 120))

# in pre-CAT stage select 5 items using DPrule and use EAP estimates
preCAT_list <- list(max_items = 5, criteria = "DPrule", method = "EAP")

# change aesthetics of GUI, including title, authors, header, and initial message
title <- "Example Test"
authors <- "I. M. D. Author"
firstpage <- list(h2("Example Test"), h5("Please answer each item to the best of your ability. ",        
       "The results of this test will remain completely anonymous ", 
       "and are only used for research purposes."))
lastpage <- function(person){
    list(h2("Thank you for completing the test."), 
         h4('Your final ability estimates are:'),
        h4(sprintf("Ability one: %.3f, SE = %.3f", person$thetas[1],
                   person$thetas_SE_history[nrow(person$thetas_SE_history), 1])),
        h4(sprintf("Ability two: %.3f, SE = %.3f", person$thetas[2],
                   person$thetas_SE_history[nrow(person$thetas_SE_history), 2])),
        h3("Please click 'Next' to close the application."))
}
demographics <- list(textInput(inputId = "occupation", label = "What is your occupation?",
    value = ""), selectInput(inputId = "gender", label = "Please select your gender.",
    choices = c("", "Male", "Female", "Other"), selected = ""))
shinyGUI_list <- list(title = title, authors = authors, demographics = demographics,
    demographics_inputIDs = c("occupation", "gender"), firstpage = firstpage, lastpage = lastpage)

# run the customized GUI interface
results <- mirtCAT(df = df, mo = mod, criteria = "Drule", start_item = "DPrule",
    shinyGUI = shinyGUI_list, design = design_list, preCAT = preCAT_list)