tests/testthat/test-0-9-m2-irt-foundations.R

test_that("transparent IRT probability and information functions obey contracts", {
  th <- seq(-3, 3, length.out = 41)
  p2 <- eyeprocess_irt_2pl_probability(th, a = 1.3, b = .2)
  expect_true(all(p2 > 0 & p2 < 1))
  expect_true(all(diff(p2) > 0))
  grm <- eyeprocess_irt_grm_probability(th, a = 1.2, thresholds = c(-1, 0, 1))
  gpcm <- eyeprocess_irt_gpcm_probability(th, a = 1.1, steps = c(-.5, .5))
  nom <- eyeprocess_irt_nominal_probability(th, slopes = c(-1, 0, 1), intercepts = c(0, .3, -.2))
  expect_equal(rowSums(grm), rep(1, length(th)), tolerance = 1e-10)
  expect_equal(rowSums(gpcm), rep(1, length(th)), tolerance = 1e-10)
  expect_equal(rowSums(nom), rep(1, length(th)), tolerance = 1e-10)
  items <- data.frame(item_id = paste0("I", 1:4), a = c(.8, 1, 1.2, 1.4), b = c(-1, -.2, .4, 1), c = 0, d = 1)
  info <- eyeprocess_irt_test_information(th, items)
  expect_s3_class(info, "eye_irt_information_profile")
  expect_true(all(info$information >= 0))
  expect_true(all(info$conditional_sem > 0))
})

test_that("identification and sparse design audits are explicit", {
  sp <- eyeprocess_irt_model_spec("2pl")
  a <- eyeprocess_irt_identification_audit(sp, constraints = list(theta_mean_fixed = TRUE, theta_sd_fixed = TRUE))
  expect_true(a$valid)
  d <- data.frame(person = c(1,1,2,2,3), item = c("A","B","A","C","B"), response = c(1,0,1,NA,1))
  s <- eyeprocess_irt_sparse_design_audit(d, person = "person", item = "item", response = "response", min_person_items = 1, min_item_persons = 1)
  expect_s3_class(s, "eye_irt_sparse_design_audit")
  expect_true(s$n_observed < nrow(d))
})

test_that("IRT information validates asymptotes and target-grid overlap", {
  expect_error(eyeprocess_irt_item_information(0,"3pl",c=1))
  expect_error(eyeprocess_irt_item_information(0,"4pl",c=.8,d=.7))
  items <- data.frame(item_id=paste0("I",1:3),a=1,b=c(-1,0,1),c=0,d=1)
  expect_error(eyeprocess_irt_measurement_precision_profile(c(-4,-3,3,4),items,target=c(-1,1)))
})

Try the eyeprocess package in your browser

Any scripts or data that you put into this service are public.

eyeprocess documentation built on Sept. 28, 2026, 5:08 p.m.