## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(collapse = TRUE, comment = "#>")
library(meow)

## ----eval = FALSE-------------------------------------------------------------
# select_sequential <- function(pers, item, R, admin, adj_mat = NULL) {
#   if (!any(admin != 0)) {
#     admin[, seq_len(min(5, ncol(admin)))] <- 1L  # seed the first five items
#     return(admin)
#   }
#   unadmin <- admin == 0
#   has <- which(rowSums(unadmin) > 0)
#   nextcol <- max.col(unadmin[has, , drop = FALSE] + 0, ties.method = "first")
#   admin[cbind(has, nextcol)] <- 1L
#   admin
# }

## -----------------------------------------------------------------------------
select_targeted <- function(pers, item, R, admin, adj_mat = NULL) {
  if (!any(admin != 0)) {
    admin[, seq_len(min(5, ncol(admin)))] <- 1L
    return(admin)
  }
  for (i in which(rowSums(admin == 0) > 0)) {
    remaining <- which(admin[i, ] == 0)
    gap <- abs(item$b[remaining] - pers$theta[i])
    admin[i, remaining[which.min(gap)]] <- 1L
  }
  admin
}

## -----------------------------------------------------------------------------
sim <- meow(
  select_fun  = select_targeted,
  update_fun  = update_theta_mle,
  data_loader = data_simple_1pl,
  data_args   = list(N_persons = 50, N_items = 30),
  fix         = "item"
)
nrow(sim$results)

