tests/testthat/test-2pl-regression.R

# irtc.mml.2pl must reproduce IRTC's baselined estimates on the bundled
# example data. References are generated by irtc.mml.2pl itself
# (see scripts/gen_reference.R) and act as a self-contained regression oracle.

test_that("irtc.mml.2pl reproduces baselined 2PL estimates", {
  data(data.sim.rasch)
  m <- irtc.mml.2pl(resp = data.sim.rasch, irtmodel = "2PL", verbose = FALSE)
  ref <- readRDS(test_path("fixtures", "ref_2pl.rds"))
  expect_equal(as.numeric(m$xsi$xsi), ref$xsi, tolerance = 1e-6)
  expect_equal(as.numeric(m$B), ref$B, tolerance = 1e-6)
  expect_equal(as.numeric(m$beta), ref$beta, tolerance = 1e-6)
  expect_equal(as.numeric(m$deviance), ref$deviance, tolerance = 1e-6)
})

test_that("irtc.mml.2pl reproduces baselined GPCM estimates", {
  data(data.gpcm)
  m <- irtc.mml.2pl(resp = data.gpcm, irtmodel = "GPCM", verbose = FALSE)
  ref <- readRDS(test_path("fixtures", "ref_gpcm2pl.rds"))
  expect_equal(as.numeric(m$xsi$xsi), ref$xsi, tolerance = 1e-6)
  expect_equal(as.numeric(m$B), ref$B, tolerance = 1e-6)
  expect_equal(as.numeric(m$deviance), ref$deviance, tolerance = 1e-6)
})

test_that("irtc.mml.2pl supports the 2PL.groups variant", {
  data(data.sim.rasch)
  grp <- rep(1:2, length.out = ncol(data.sim.rasch))
  m <- irtc.mml.2pl(resp = data.sim.rasch, irtmodel = "2PL.groups",
                    est.slopegroups = grp, verbose = FALSE)
  expect_s3_class(m, "irtc")
  expect_true(is.finite(as.numeric(m$deviance)))
})

Try the IRTC package in your browser

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

IRTC documentation built on July 24, 2026, 5:07 p.m.