# NOT RUN {
library(dplyr)
# generate a 100-item pool
items <- irt_model("3pl")$gendata(1, 100)$items
items$id <- 1:nrow(items)
items$content <- sample(1:3, nrow(items), replace=TRUE)
items$time <- round(rlnorm(nrow(items), log(60), .2), 0)
## ex. 1: 6 forms, 10 items, maximize b parmaters
## solved by GLPK and LpSolve respectively
x <- ata(items, 6, len=10, maxselect=1)
x <- ata_obj_relative(x, "b", "max")
glpk <- ata_solve(x, solver="glpk")
glpk$optimum
sapply(glpk$items, function(x)
c(mean=mean(x$b), sd=sd(x$b), min=min(x$b), max=max(x$b)))
lpsolve <- ata_solve(x, solver="lpsolve")
lpsolve$optimum
sapply(lpsolve$items, function(x)
c(mean=mean(x$b), sd=sd(x$b), min=min(x$b), max=max(x$b)))
## ex. 2: 4 forms, 10 items, minimize b parmaeters
x <- ata(items, 3, len=10, maxselect=1)
x <- ata_obj_relative(x, "b", "min", negative=TRUE)
glpk <- ata_solve(x, solver="glpk", as.list=FALSE, timeout=5)
group_by(glpk$items, form) %>%
summarise(mean=mean(b), sd=sd(b), min=min(b), max=max(b))
lpsolve <- ata_solve(x, solver="lpsolve", as.list=FALSE, timeout=5)
group_by(lpsolve$items, form) %>%
summarise(mean=mean(b), sd=sd(b), min=min(b), max=max(b))
## ex. 3: 3 forms, 10 items, maximize information at -1 and 1
## content distribution: 3, 3, 4
## response time: avg. 55-65 seconds
x <- ata(items, 3, len=10, maxselect=1)
x <- ata_obj_relative(x, c(-1, 1), "max")
x <- ata_constraint(x, "content", min=3, max=3, level=1)
x <- ata_constraint(x, "content", min=3, max=3, level=2)
x <- ata_constraint(x, "content", min=4, max=4, level=3)
x <- ata_constraint(x, "time", min=55*10, max=65*10)
lpsolve <- ata_solve(x, solver="lpsolve")
lpsolve$optimum
plot(lpsolve)
sapply(lpsolve$items, function(x)
c(freq(x$content, 1:3)$freq, mean(x$time)))
## ex. 4: 2 forms, 10 items, mean(b) = 0, sd(b) = 1.0, content = (3, 3, 4)
x <- ata(items, 2, len=10, maxselect=1) %>%
ata_obj_absolute(items$b, 0 * 10) %>%
ata_obj_absolute((items$b - 0)^2, 1 * 10) %>%
ata_constraint("content", min=3, max=3, level=1) %>%
ata_constraint("content", min=3, max=3, level=2) %>%
ata_constraint("content", min=4, max=4, level=3)
lpsolve <- ata_solve(x, "lpsolve", verbose="normal", timeout=5)
sapply(lpsolve$items, function(x) c(mean=mean(x$b), sd=sd(x$b)))
# ex. 5: 2 forms, 10 items, flat TIF over [-1, 1]
x <- ata(items, 2, len=10, maxselect=1) %>%
ata_obj_relative(seq(-1, 1, .5), "max", flatten=0.05)
x <- ata_solve(x, "lpsolve")
plot(x)
# }
Run the code above in your browser using DataLab