Learn R Programming

mirtCAT (version 1.2)

extract.mirtCAT: Extract elements from the internal person, test, and design objects

Description

This function extracts elements, as well as builds a few convenient elements, from the three internal person, design, or test objects that are accessible through a customNextItem function definition (see mirtCAT for details).

Usage

extract.mirtCAT(x, what)

The 'person' argument

The 'design' argument

The 'test' argument

Details

Depending on which object is supplied, the following elements can be extracted.

See Also

mirt, mirtCAT, extract.mirt, findNextItem

Examples

Run this code

 #example test
set.seed(1234)
nitems <- 25
itemnames <- paste0('Item.', 1:nitems)
a <- matrix(rlnorm(nitems, .2, .3))
d <- matrix(rnorm(nitems))
dat <- simdata(a, d, 500, itemtype = 'dich')
colnames(dat) <- itemnames
mod <- mirt(dat, 1, verbose = FALSE, TOL = .01)

# 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)
df$Answer <- answers

pat <- generate_pattern(mod, Theta = 0, df)

#------------------------------------------------
# administer items in sequence
customNextItem <- function(person, design, test){
   # browser()
   items_left_2_choose_from <- extract.mirtCAT(person, 'items_in_bank')
   min(items_left_2_choose_from)
}

res <- mirtCAT(df, local_pattern=pat, 
  design = list(customNextItem=customNextItem))
summary(res)

#------------------------------------------------
# administer items in order, but stop after 10 items
customNextItem <- function(person, design, test){
   items_left_2_choose_from <- extract.mirtCAT(person, 'items_in_bank')
   items_answered <- extract.mirtCAT(person, 'items_answered')
   total <- sum(!is.na(items_answered))
   ret <- if(total < 10) min(items_left_2_choose_from)
     else return(NA)
   ret
}

res <- mirtCAT(df, local_pattern=pat, 
  design = list(customNextItem=customNextItem))
summary(res)

#------------------------------------------------
# using findNextItem() and stopping after 10 items

customNextItem <- function(person, design, test){
   items_answered <- extract.mirtCAT(person, 'items_answered')
   total <- sum(!is.na(items_answered))
   ret <- NA
   if(total < 10) 
     ret <- findNextItem(person=person, test=test, design=design, criteria = 'MI')
   ret
}

res <- mirtCAT(df, mod, local_pattern=pat, start_item = 'MI',
  design = list(customNextItem=customNextItem))
summary(res)

# equivalent to the following
res2 <- mirtCAT(df, mod, local_pattern=pat, start_item = 'MI', 
  criteria = 'MI', design = list(max_items = 10))
summary(res2)

Run the code above in your browser using DataLab