Items, raters and rating scales: 2PL IRT and many-facet Rasch
When systems answer benchmark items, or raters score essays on a 1–5 scale, put abilities, item difficulty and rater severity on one latent scale. Learn the 2PL model and item information, then the many-facet Rasch model for raters.
What runs in CodeSplash
- HME008Two-parameter logistic item-response model (2PL IRT) Runs in CodeSplash
- HME009Many-facet Rasch measurement model Runs in CodeSplash
- Item response theory (Rasch, 2PL, graded response) Verified in Python and R
- Many-facet Rasch model (rater severity) Verified in Python and R
You will be able to
- Write the 2PL item response function and its item information
- Compare Rasch and 2PL fits by AIC, BIC and absolute fit
- Write the many-facet Rasch adjacent-category logit with person, item, rater and threshold terms
- Explain why raters must be linked through shared persons or items
Items have difficulty and sharpness
ReadA benchmark score adds up right answers, as if every item counted the same. Item response theoryItem response theoryModels the chance of each response to each item from a person's latent trait and the item's own parameters. models each response instead. In the two-parameter logistic (2PL) model, a respondent with ability answers item correctly with
is the item's difficultyItem difficultyThe trait level at which a person has a 50% chance of endorsing or passing an item. (the ability with a 50% chance) and its discriminationItem discriminationHow sharply an item separates people slightly below and slightly above its difficulty. (how sharply it separates abilities near ). Rasch fixes every equal. The scale's origin and unit need a convention, usually abilities with mean 0 and SD 1.
Reference · HME008 · Runs in CodeSplashTwo-parameter logistic item-response model (2PL IRT)Model binary item responses using respondent ability plus item difficulty and discrimination. It can distinguish an item’s location on the latent scale from how sharply it separates abilities.Item information
ReadHow much does one item tell you about ability? Its item informationItem informationHow much an item sharpens the ability estimate at each ability level; in the 2PL it is a² p (1 − p), peaking at the item's difficulty. is
largest at and larger for sharper items. In the reference's example, a sharp item (, ) gives information 0.713 to a respondent at ability 1, while a flat one () gives only 0.097 there. Summing over items gives test information, the precision of an ability estimate; adaptive tests pick the next item with the most information at the current estimate.
Rasch or 2PL?
ReadItem response theory (Rasch, 2PL, graded response) fits both by marginal maximum likelihood (EM over the ability distribution), on five LSAT items here.
Two-parameter logistic (2PL) model: log-likelihood = −2658.81, AIC = 5337.6, BIC = 5386.7
- Log-likelihood
- −2658.81
- AIC
- 5337.61
- BIC
- 5386.69
- Empirical reliability
- 0.4521
Plots
View data
| Item | Probability | Trait (θ) |
|---|---|---|
| item_1 | 0.1096 | −4 |
| item_1 | 0.1197 | −3.900 |
| item_1 | 0.1305 | −3.800 |
| item_1 | 0.1421 | −3.700 |
| item_1 | 0.1546 | −3.600 |
| item_1 | 0.1679 | −3.500 |
| item_1 | 0.1822 | −3.400 |
| item_1 | 0.1973 | −3.300 |
| item_1 | 0.2134 | −3.200 |
| item_1 | 0.2305 | −3.100 |
| item_1 | 0.2485 | −3 |
| item_1 | 0.2674 | −2.900 |
| item_1 | 0.2871 | −2.800 |
| item_1 | 0.3078 | −2.700 |
| item_1 | 0.3292 | −2.600 |
| item_1 | 0.3514 | −2.500 |
| item_1 | 0.3742 | −2.400 |
| item_1 | 0.3976 | −2.300 |
| item_1 | 0.4215 | −2.200 |
| item_1 | 0.4457 | −2.100 |
| item_1 | 0.4702 | −2 |
| item_1 | 0.4949 | −1.900 |
| item_1 | 0.5196 | −1.800 |
| item_1 | 0.5441 | −1.700 |
| item_1 | 0.5685 | −1.600 |
| item_1 | 0.5926 | −1.500 |
| item_1 | 0.6162 | −1.400 |
| item_1 | 0.6392 | −1.300 |
| item_1 | 0.6617 | −1.200 |
| item_1 | 0.6834 | −1.100 |
| item_1 | 0.7044 | −1 |
| item_1 | 0.7245 | −0.9000 |
| item_1 | 0.7438 | −0.8000 |
| item_1 | 0.7622 | −0.7000 |
| item_1 | 0.7796 | −0.6000 |
| item_1 | 0.7961 | −0.5000 |
| item_1 | 0.8117 | −0.4000 |
| item_1 | 0.8263 | −0.3000 |
| item_1 | 0.8400 | −0.2000 |
| item_1 | 0.8528 | −0.1000 |
| item_1 | 0.8648 | 0 |
| item_1 | 0.8759 | 0.1000 |
| item_1 | 0.8863 | 0.2000 |
| item_1 | 0.8959 | 0.3000 |
| item_1 | 0.9047 | 0.4000 |
| item_1 | 0.9129 | 0.5000 |
| item_1 | 0.9204 | 0.6000 |
| item_1 | 0.9274 | 0.7000 |
| item_1 | 0.9338 | 0.8000 |
| item_1 | 0.9396 | 0.9000 |
| item_1 | 0.9450 | 1 |
| item_1 | 0.9499 | 1.100 |
| item_1 | 0.9544 | 1.200 |
| item_1 | 0.9585 | 1.300 |
| item_1 | 0.9623 | 1.400 |
| item_1 | 0.9657 | 1.500 |
| item_1 | 0.9688 | 1.600 |
| item_1 | 0.9717 | 1.700 |
| item_1 | 0.9743 | 1.800 |
| item_1 | 0.9766 | 1.900 |
First 60 of 405 rows.
View data
| Information | Standard error | Trait (θ) |
|---|---|---|
| 0.2874 | 1.865 | −4 |
| 0.3082 | 1.801 | −3.900 |
| 0.3303 | 1.740 | −3.800 |
| 0.3540 | 1.681 | −3.700 |
| 0.3791 | 1.624 | −3.600 |
| 0.4060 | 1.569 | −3.500 |
| 0.4346 | 1.517 | −3.400 |
| 0.4650 | 1.466 | −3.300 |
| 0.4975 | 1.418 | −3.200 |
| 0.5321 | 1.371 | −3.100 |
| 0.5691 | 1.326 | −3 |
| 0.6084 | 1.282 | −2.900 |
| 0.6503 | 1.240 | −2.800 |
| 0.6949 | 1.200 | −2.700 |
| 0.7423 | 1.161 | −2.600 |
| 0.7925 | 1.123 | −2.500 |
| 0.8456 | 1.087 | −2.400 |
| 0.9014 | 1.053 | −2.300 |
| 0.9597 | 1.021 | −2.200 |
| 1.020 | 0.9902 | −2.100 |
| 1.082 | 0.9616 | −2 |
| 1.144 | 0.9351 | −1.900 |
| 1.205 | 0.9111 | −1.800 |
| 1.264 | 0.8896 | −1.700 |
| 1.318 | 0.8709 | −1.600 |
| 1.367 | 0.8552 | −1.500 |
| 1.408 | 0.8427 | −1.400 |
| 1.439 | 0.8335 | −1.300 |
| 1.459 | 0.8278 | −1.200 |
| 1.467 | 0.8258 | −1.100 |
| 1.461 | 0.8274 | −1 |
| 1.442 | 0.8327 | −0.9000 |
| 1.411 | 0.8418 | −0.8000 |
| 1.369 | 0.8547 | −0.7000 |
| 1.317 | 0.8712 | −0.6000 |
| 1.258 | 0.8914 | −0.5000 |
| 1.194 | 0.9152 | −0.4000 |
| 1.126 | 0.9423 | −0.3000 |
| 1.056 | 0.9729 | −0.2000 |
| 0.9867 | 1.007 | −0.1000 |
| 0.9181 | 1.044 | 0 |
| 0.8515 | 1.084 | 0.1000 |
| 0.7876 | 1.127 | 0.2000 |
| 0.7271 | 1.173 | 0.3000 |
| 0.6700 | 1.222 | 0.4000 |
| 0.6166 | 1.273 | 0.5000 |
| 0.5669 | 1.328 | 0.6000 |
| 0.5207 | 1.386 | 0.7000 |
| 0.4780 | 1.446 | 0.8000 |
| 0.4386 | 1.510 | 0.9000 |
| 0.4024 | 1.576 | 1 |
| 0.3690 | 1.646 | 1.100 |
| 0.3384 | 1.719 | 1.200 |
| 0.3102 | 1.795 | 1.300 |
| 0.2844 | 1.875 | 1.400 |
| 0.2607 | 1.958 | 1.500 |
| 0.2390 | 2.045 | 1.600 |
| 0.2191 | 2.136 | 1.700 |
| 0.2009 | 2.231 | 1.800 |
| 0.1842 | 2.330 | 1.900 |
First 60 of 81 rows.
View data
| With | Text | Item | Q3 |
|---|---|---|---|
| item_1 | item_1 | 0 | |
| item_2 | -0.13 | item_1 | −0.1345 |
| item_3 | -0.21 | item_1 | −0.2137 |
| item_4 | -0.01 | item_1 | −0.0121 |
| item_5 | 0.01 | item_1 | 0.0087 |
| item_1 | -0.13 | item_2 | −0.1345 |
| item_2 | item_2 | 0 | |
| item_3 | -0.16 | item_2 | −0.1628 |
| item_4 | -0.13 | item_2 | −0.1339 |
| item_5 | -0.12 | item_2 | −0.1245 |
| item_1 | -0.21 | item_3 | −0.2137 |
| item_2 | -0.16 | item_3 | −0.1628 |
| item_3 | item_3 | 0 | |
| item_4 | -0.17 | item_3 | −0.1698 |
| item_5 | -0.11 | item_3 | −0.1147 |
| item_1 | -0.01 | item_4 | −0.0121 |
| item_2 | -0.13 | item_4 | −0.1339 |
| item_3 | -0.17 | item_4 | −0.1698 |
| item_4 | item_4 | 0 | |
| item_5 | -0.05 | item_4 | −0.0545 |
| item_1 | 0.01 | item_5 | 0.0087 |
| item_2 | -0.12 | item_5 | −0.1245 |
| item_3 | -0.11 | item_5 | −0.1147 |
| item_4 | -0.05 | item_5 | −0.0545 |
| item_5 | item_5 | 0 |
Assumptions
- One underlying trait — Assumed by the model; check it with a one-factor analysis (exploratory factor analysis or CFA) of the items.
- Sample size — 1000 respondents for 10 parameters.
- Category use — Every category has at least 10 responses.
- Convergence — EM converged in 107 cycles.
- Item fit — S-X² flags item_2 (Holm-adjusted p < .05): the model describes this item poorly.
- Local independence — Largest Q3 0.009 against an average of -0.111; no pair is more than 0.2 above the average.
Item parameters (IRT form: logit = a(θ − b))
| Item | Discrimination a | SE | Difficulty b | SE |
|---|---|---|---|---|
| item_1 | 0.9875 | 0.1772 | −1.879 | 0.2640 |
| item_2 | 1.081 | 0.1688 | −0.7475 | 0.1093 |
| item_3 | 1.707 | 0.3211 | −1.057 | 0.1154 |
| item_4 | 0.7650 | 0.1341 | −0.6353 | 0.1301 |
| item_5 | 0.7357 | 0.1511 | −2.521 | 0.4463 |
Person scores (EAP)
| Value | |
|---|---|
| Mean | 4.939e-10 |
| SD | 0.6724 |
| Mean posterior SD | 0.7402 |
| Empirical reliability | 0.4521 |
Item fit (S-X²)
| Item | S-X² | df | p | p (Holm) | RMSEA |
|---|---|---|---|---|---|
| item_1 | 4.751 | 2 | .093 | .292 | 0.0371 |
| item_2 | 14.453 | 2 | < .001 | .004 | 0.0789 |
| item_3 | 1.273 | 2 | .529 | 1.000 | 0 |
| item_4 | 5.236 | 2 | .073 | .292 | 0.0402 |
| item_5 | 0.9409 | 2 | .625 | 1.000 | 0 |
Limited-information fit
| Measure | Value |
|---|---|
| M2 | 11.938 |
| df | 5 |
| p | 0.0356 |
| RMSEA2 | 0.0373 |
| RMSEA2 90% CI low | 0.0090 |
| RMSEA2 90% CI high | 0.0650 |
| SRMSR | 0.0320 |
- Marginal maximum likelihood (EM over 61 points on [−6, 6], θ ~ N(0, 1)); standard errors from the observed information; 107 EM cycles. Categories: item_1: 0, 1; item_2: 0, 1; item_3: 0, 1; item_4: 0, 1; item_5: 0, 1
The exact R script · R R version 4.5.1 (2025-06-13)
# Item response theory (Rasch, 2PL, graded response)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method measurement.irt 1.1.0 · spec f45cc74bb0458728
# Dataset: s3_lsat7 (version 1)
# Runs on its own: outside the app, cs_publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
library(codesplashr)
# mirt::mirt(data, 1, itemtype = "2PL" | "graded" | "Rasch") fits the same models on the same grid;
# cs_meas_irt_fit adds observed-information standard errors and keeps R and Python identical.
# %% Data (missing responses are kept; respondents with no response are left out)
items <- c("item_1", "item_2", "item_3", "item_4", "item_5")
kinds <- c(
"item_1" = "numeric",
"item_2" = "numeric",
"item_3" = "numeric",
"item_4" = "numeric",
"item_5" = "numeric"
)
stored <- list(
"item_1" = NULL,
"item_2" = NULL,
"item_3" = NULL,
"item_4" = NULL,
"item_5" = NULL
)
df <- as.data.frame(nanoparquet::read_parquet("tests/parity/fixtures/s3_lsat7.parquet", col_select = items))
warnings <- list()
codes <- matrix(NA_real_, nrow(df), length(items))
categories <- list()
for (j in seq_along(items)) {
it <- items[j]
if (kinds[[it]] == "numeric") {
x <- as.double(df[[it]])
cs_check_finite(x, it) # infinite values stop the run (registry/errors.yaml)
vals <- sort(unique(x[!is.na(x)]))
codes[, j] <- match(x, vals) - 1
labels <- vapply(vals, function(v) if (v == round(v)) sprintf("%.0f", v) else formatC(v, digits = 15, format = "g"), character(1))
} else {
v <- df[[it]]
t <- ifelse(is.na(v), NA_character_, if (is.logical(v)) tolower(as.character(v)) else as.character(v))
ord <- if (!is.null(stored[[it]])) stored[[it]] else sort(unique(stats::na.omit(t)), method = "radix")
used <- ord[ord %in% t]
if (length(used) < length(ord)) warnings <- c(warnings, sprintf("%s: categories nobody chose were dropped (%s).", it, paste(setdiff(ord, used), collapse = ", ")))
codes[, j] <- match(t, used) - 1
labels <- used
}
if (length(labels) == 0) cs_error("CS_E_ALL_MISSING", column = it)
if (length(labels) < 2) cs_error("CS_E_CONSTANT", column = it) # one response category: nothing to scale
categories[[j]] <- labels
}
answered <- rowSums(!is.na(codes)) > 0
if (any(!answered)) warnings <- c(warnings, sprintf("%d respondents without any response were left out.", sum(!answered)))
codes <- codes[answered, , drop = FALSE]
n <- nrow(codes)
binary <- all(vapply(categories, length, integer(1)) == 2)
model <- "auto"
if (model == "auto") model <- if (binary) "2pl" else "grm"
if (model %in% c("rasch", "2pl") && !binary) stop("The Rasch and 2PL models need right/wrong items; use the graded response model for more categories")
model_label <- c(rasch = "Rasch (1PL) model", "2pl" = "Two-parameter logistic (2PL) model", grm = "Graded response model")[[model]]
lcfirst <- function(s) paste0(tolower(substr(s, 1, 1)), substr(s, 2, nchar(s)))
# %% Fit (marginal maximum likelihood, EM on 61 quadrature points)
fit <- tryCatch(cs_meas_irt_fit(codes, model), error = function(e) {
# a singular information matrix: estimates run off, e.g. an item that separates respondents perfectly
if (grepl("singular", conditionMessage(e), fixed = TRUE)) cs_error("CS_E_NO_CONVERGENCE", what = c(rasch = "The Rasch model", "2pl" = "The 2PL model", grm = "The graded response model")[[model]])
stop(e)
})
tab <- cs_meas_irt_items(fit)
npar <- fit$npar
loglik <- fit$loglik
eap <- fit$eap
psd <- fit$psd
var_eap <- mean((eap - mean(eap))^2)
reliability <- var_eap / (var_eap + mean(psd^2))
values <- list(n = n, items = length(items), npar = npar, loglik = loglik, aic = -2 * loglik + 2 * npar, bic = -2 * loglik + npar * log(n),
reliability = reliability, eap_mean = mean(eap), eap_sd = sqrt(var_eap), model_label = model_label)
rows <- list()
kmax <- max(vapply(categories, length, integer(1)))
for (j in seq_along(items)) {
it <- items[j]
r <- tab[[j]]
values[[sprintf("a[%s]", it)]] <- r$a
values[[sprintf("se_a[%s]", it)]] <- r$se_a
row <- list(item = it, a = r$a, se_a = r$se_a)
if (length(categories[[j]]) == 2) {
values[[sprintf("b[%s]", it)]] <- r$b[1]
values[[sprintf("se_b[%s]", it)]] <- r$se_b[1]
row$b1 <- r$b[1]
row$se_b1 <- r$se_b[1]
} else {
for (m in seq_along(r$b)) {
values[[sprintf("b[%s|%d]", it, m)]] <- r$b[m]
values[[sprintf("se_b[%s|%d]", it, m)]] <- r$se_b[m]
row[[sprintf("b%d", m)]] <- r$b[m]
row[[sprintf("se_b%d", m)]] <- r$se_b[m]
}
}
rows[[j]] <- row
}
# %% Item and model fit: S-X² per item (Orlando & Thissen; mirt's cell collapsing), M2 / M2* with RMSEA2
# and SRMSR (Maydeu-Olivares & Joe), Yen's Q3 at the EAP scores — mirt::itemfit, M2 and residuals compute the same
diag <- cs_meas_irt_diagnostics(fit, codes, items)
for (k in names(diag$values)) values[k] <- list(diag$values[[k]])
# %% Assumptions
sparse <- character(0)
for (j in seq_along(items)) {
cats <- categories[[j]]
counts <- vapply(seq_along(cats) - 1, function(c0) sum(codes[, j] == c0, na.rm = TRUE), numeric(1))
sparse <- c(sparse, sprintf("%s = %s (%d)", items[j], cats, counts)[counts < 10])
}
need <- if (model != "grm") 200 else 500
assumptions <- list(
list(key = "unidimensionality", label = "One underlying trait", status = "info",
detail = "Assumed by the model; check it with a one-factor analysis (exploratory factor analysis or CFA) of the items."),
list(key = "sample_size", label = "Sample size", status = if (n < need) "warn" else "pass",
detail = paste0(sprintf("%d respondents for %d parameters", n, npar), if (n < need) sprintf(" — %d or more are usually recommended for the %s.", need, lcfirst(model_label)) else ".")),
list(key = "categories", label = "Category use", status = if (length(sparse)) "warn" else "pass",
detail = if (length(sparse)) paste0("Fewer than 10 responses: ", paste(utils::head(sparse, 8), collapse = "; "), if (length(sparse) > 8) " …" else "", ".")
else "Every category has at least 10 responses."),
list(key = "convergence", label = "Convergence", status = if (fit$converged) "pass" else "warn",
detail = if (fit$converged) sprintf("EM converged in %d cycles.", fit$iterations) else sprintf("EM stopped after %d cycles without converging.", fit$iterations))
)
assumptions <- c(assumptions, diag$assumptions) # item fit (S-X², Holm-adjusted) and local independence (Q3 more than 0.2 above its average)
# %% Result
cols <- list(list(key = "item", label = "Item", type = "string"), list(key = "a", label = "Discrimination a", type = "number"),
list(key = "se_a", label = "SE", type = "number"))
for (m in seq_len(kmax - 1)) {
cols <- c(cols, list(list(key = sprintf("b%d", m), label = if (kmax == 2) "Difficulty b" else sprintf("Threshold b%d", m), type = "number"),
list(key = sprintf("se_b%d", m), label = "SE", type = "number")))
}
theta <- round((-40:40) / 10, 10)
info <- cs_meas_irt_information(fit, theta)
curve_t <- numeric(0)
curve_p <- numeric(0)
curve_i <- character(0)
curve_c <- character(0)
for (j in seq_along(items)) {
P <- cs_meas_cat_probs(fit$params[[j]]$a, fit$params[[j]]$d, theta)
cats <- categories[[j]]
shown <- if (length(cats) == 2) length(cats) else seq_along(cats)
for (c0 in shown) {
curve_t <- c(curve_t, theta)
curve_p <- c(curve_p, P[, c0])
curve_i <- c(curve_i, rep(items[j], length(theta)))
curve_c <- c(curve_c, rep(cats[c0], length(theta)))
}
}
total <- colSums(info)
curve_roles <- list(
theta = cs_col("Trait (θ)", curve_t, "numeric"),
probability = cs_col("Probability", curve_p, "numeric"),
item = cs_col("Item", curve_i, "categorical", levels = items)
)
if (!binary) curve_roles$category <- cs_col("Category", curve_c, "categorical")
charts <- list(
cs_chart("curves", "item-curves", if (binary) "Item characteristic curves" else "Category response curves", curve_roles, controls = list(kind = "icc")),
cs_chart("information", "test-information", "Test information", list(
theta = cs_col("Trait (θ)", theta, "numeric"),
information = cs_col("Information", total, "numeric"),
se = cs_col("Standard error", 1 / sqrt(total), "numeric")
))
)
q3 <- diag$q3
qc <- expand.grid(j = seq_along(items), i = seq_along(items))
show <- qc$i != qc$j & is.finite(q3[cbind(qc$i, qc$j)])
charts <- c(charts, list(cs_chart("q3", "matrix-heatmap", "Residual correlations (Q3)", list(
row = cs_col("Item", items[qc$i], "categorical", levels = items),
col = cs_col("With", items[qc$j], "categorical", levels = items),
value = cs_col("Q3", ifelse(show, q3[cbind(qc$i, qc$j)], 0), "numeric"),
label = cs_col("Text", ifelse(show, sprintf("%.2f", q3[cbind(qc$i, qc$j)]), ""), "categorical")
), controls = list(scale = "diverging"))))
cat_note <- substr(paste(vapply(seq_along(items), function(j) sprintf("%s: %s", items[j], paste(categories[[j]], collapse = ", ")), character(1)), collapse = "; "), 1, 600)
cs_publish(list(
method = "measurement.irt",
methodVersion = "1.1.0",
title = model_label,
engine = cs_engine_info("stats", "codesplashr"),
n = n,
summary = sprintf("%s for %d items and %d respondents: log-likelihood %.2f, empirical reliability %.2f.", model_label, length(items), n, loglik, reliability),
apa = sprintf("%s: log-likelihood = %s, AIC = %s, BIC = %s", model_label, cs_fmt_num(loglik), cs_fmt_num(values$aic, 1), cs_fmt_num(values$bic, 1)),
statistics = list(list(key = "loglik", label = "Log-likelihood", value = loglik), list(key = "aic", label = "AIC", value = values$aic),
list(key = "bic", label = "BIC", value = values$bic), list(key = "reliability", label = "Empirical reliability", value = reliability)),
tables = c(list(
list(key = "items", title = "Item parameters (IRT form: logit = a(θ − b))", columns = cols, rows = rows),
list(key = "persons", title = "Person scores (EAP)", columns = list(list(key = "stat", label = "", type = "string"), list(key = "value", label = "Value", type = "number")),
rows = list(list(stat = "Mean", value = mean(eap)), list(stat = "SD", value = sqrt(var_eap)),
list(stat = "Mean posterior SD", value = sqrt(mean(psd^2))), list(stat = "Empirical reliability", value = reliability)))
), diag$tables),
assumptions = assumptions,
warnings = warnings,
notes = c(list(paste0(sprintf("Marginal maximum likelihood (EM over 61 points on [−6, 6], θ ~ N(0, 1)); standard errors from the observed information; %d EM cycles. Categories: ", fit$iterations), cat_note)),
diag$notes),
charts = charts,
values = values
))
Two-parameter logistic (2PL) model: log-likelihood = −2658.81, AIC = 5337.6, BIC = 5386.7
- Log-likelihood
- −2658.81
- AIC
- 5337.61
- BIC
- 5386.69
- Empirical reliability
- 0.4521
To keep this page light, the plots are shown once, under the R tab.
Assumptions
- One underlying trait — Assumed by the model; check it with a one-factor analysis (exploratory factor analysis or CFA) of the items.
- Sample size — 1000 respondents for 10 parameters.
- Category use — Every category has at least 10 responses.
- Convergence — EM converged in 107 cycles.
- Item fit — S-X² flags item_2 (Holm-adjusted p < .05): the model describes this item poorly.
- Local independence — Largest Q3 0.009 against an average of -0.111; no pair is more than 0.2 above the average.
Item parameters (IRT form: logit = a(θ − b))
| Item | Discrimination a | SE | Difficulty b | SE |
|---|---|---|---|---|
| item_1 | 0.9875 | 0.1772 | −1.879 | 0.2640 |
| item_2 | 1.081 | 0.1688 | −0.7475 | 0.1093 |
| item_3 | 1.707 | 0.3211 | −1.057 | 0.1154 |
| item_4 | 0.7650 | 0.1341 | −0.6353 | 0.1301 |
| item_5 | 0.7357 | 0.1511 | −2.521 | 0.4463 |
Person scores (EAP)
| Value | |
|---|---|
| Mean | 4.939e-10 |
| SD | 0.6724 |
| Mean posterior SD | 0.7402 |
| Empirical reliability | 0.4521 |
Item fit (S-X²)
| Item | S-X² | df | p | p (Holm) | RMSEA |
|---|---|---|---|---|---|
| item_1 | 4.751 | 2 | .093 | .292 | 0.0371 |
| item_2 | 14.453 | 2 | < .001 | .004 | 0.0789 |
| item_3 | 1.273 | 2 | .529 | 1.000 | 0 |
| item_4 | 5.236 | 2 | .073 | .292 | 0.0402 |
| item_5 | 0.9409 | 2 | .625 | 1.000 | 0 |
Limited-information fit
| Measure | Value |
|---|---|
| M2 | 11.938 |
| df | 5 |
| p | 0.0356 |
| RMSEA2 | 0.0373 |
| RMSEA2 90% CI low | 0.0090 |
| RMSEA2 90% CI high | 0.0650 |
| SRMSR | 0.0320 |
- Marginal maximum likelihood (EM over 61 points on [−6, 6], θ ~ N(0, 1)); standard errors from the observed information; 107 EM cycles. Categories: item_1: 0, 1; item_2: 0, 1; item_3: 0, 1; item_4: 0, 1; item_5: 0, 1
The exact Python script · Python Python 3.13.5 · scipy 1.18.1 · pandas 3.1.0
# Item response theory (Rasch, 2PL, graded response)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method measurement.irt 1.1.0 · spec f45cc74bb0458728
# Dataset: s3_lsat7 (version 1)
# Runs on its own: outside the app, cs.publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
import json
import numpy as np
import pandas as pd
import codesplash as cs
from codesplash.errors import check_finite
from codesplash.stats import measurement as ms # MML-EM IRT twin of R's cs_meas_irt_fit
from codesplash.stats import measurement_fit as mf # S-X², M2 and Q3 twins of R's cs_meas_irt_diagnostics
# mirt::mirt(data, 1, itemtype = "2PL" | "graded" | "Rasch") fits the same models on the same grid;
# the twin adds observed-information standard errors and keeps Python and R identical.
# %% Data (missing responses are kept; respondents with no response are left out)
items = ["item_1", "item_2", "item_3", "item_4", "item_5"]
kinds = {"item_1":"numeric","item_2":"numeric","item_3":"numeric","item_4":"numeric","item_5":"numeric"}
stored = json.loads("{\"item_1\":null,\"item_2\":null,\"item_3\":null,\"item_4\":null,\"item_5\":null}")
df = pd.read_parquet("tests/parity/fixtures/s3_lsat7.parquet", columns=items)
warnings = []
n0 = len(df)
codes = np.full((n0, len(items)), np.nan)
categories = []
for j, it in enumerate(items):
if kinds[it] == "numeric":
x = df[it].to_numpy(dtype=float)
check_finite(x, it) # infinite values stop the run (registry/errors.yaml)
vals = np.unique(x[~np.isnan(x)])
codes[:, j] = np.where(np.isnan(x), np.nan, np.searchsorted(vals, np.nan_to_num(x)))
labels = [f"{v:.0f}" if float(v).is_integer() else f"{v:.15g}" for v in vals]
else:
t = [None if pd.isna(v) else (str(v).lower() if isinstance(v, (bool, np.bool_)) else str(v)) for v in df[it]]
order = stored[it] or sorted({v for v in t if v is not None})
used = [c for c in order if c in set(t)]
if len(used) < len(order):
warnings.append(f"{it}: categories nobody chose were dropped ({', '.join(c for c in order if c not in used)}).")
pos = {c: i for i, c in enumerate(used)}
codes[:, j] = [pos[v] if v is not None else np.nan for v in t]
labels = used
if len(labels) == 0:
cs.cs_error("CS_E_ALL_MISSING", column=it)
if len(labels) < 2:
cs.cs_error("CS_E_CONSTANT", column=it) # one response category: nothing to scale
categories.append(labels)
answered = np.sum(~np.isnan(codes), axis=1) > 0
if (~answered).any():
warnings.append(f"{int((~answered).sum())} respondents without any response were left out.")
codes = codes[answered]
n = codes.shape[0]
binary = all(len(c) == 2 for c in categories)
model = "auto"
if model == "auto":
model = "2pl" if binary else "grm"
if model in ("rasch", "2pl") and not binary:
raise ValueError("The Rasch and 2PL models need right/wrong items; use the graded response model for more categories")
model_label = {"rasch": "Rasch (1PL) model", "2pl": "Two-parameter logistic (2PL) model", "grm": "Graded response model"}[model]
# %% Fit (marginal maximum likelihood, EM on 61 quadrature points)
try:
fit = ms.irt_fit(codes, model)
except np.linalg.LinAlgError: # a singular information matrix: estimates run off, e.g. an item that separates respondents perfectly
cs.cs_error("CS_E_NO_CONVERGENCE", what={"rasch": "The Rasch model", "2pl": "The 2PL model", "grm": "The graded response model"}[model])
table = ms.irt_item_table(fit)
npar = fit["npar"]
loglik = fit["loglik"]
eap, psd = fit["eap"], fit["psd"]
var_eap = float(np.mean((eap - eap.mean()) ** 2))
reliability = var_eap / (var_eap + float(np.mean(psd**2)))
values = {"n": float(n), "items": float(len(items)), "npar": float(npar), "loglik": loglik, "aic": -2 * loglik + 2 * npar,
"bic": -2 * loglik + npar * np.log(n), "reliability": reliability, "eap_mean": float(eap.mean()), "eap_sd": float(np.sqrt(var_eap)),
"model_label": model_label}
rows = []
kmax = max(len(c) for c in categories)
for it, r, cats in zip(items, table, categories):
values[f"a[{it}]"] = r["a"]
values[f"se_a[{it}]"] = r["se_a"]
row = {"item": it, "a": r["a"], "se_a": r["se_a"]}
if len(cats) == 2:
values[f"b[{it}]"] = r["b"][0]
values[f"se_b[{it}]"] = r["se_b"][0]
row.update({"b1": r["b"][0], "se_b1": r["se_b"][0]})
else:
for m, (b, se) in enumerate(zip(r["b"], r["se_b"]), start=1):
values[f"b[{it}|{m}]"] = b
values[f"se_b[{it}|{m}]"] = se
row.update({f"b{m}": b, f"se_b{m}": se})
rows.append(row)
# %% Item and model fit: S-X² per item (Orlando & Thissen; mirt's cell collapsing), M2 / M2* with RMSEA2
# and SRMSR (Maydeu-Olivares & Joe), Yen's Q3 at the EAP scores — mirt::itemfit, M2 and residuals compute the same
diag = mf.irt_diagnostics(fit, codes, items)
values.update(diag["values"])
# %% Assumptions
sparse = []
for j, (it, cats) in enumerate(zip(items, categories)):
counts = [int(np.sum(codes[:, j] == c)) for c in range(len(cats))]
sparse += [f"{it} = {cats[c]} ({counts[c]})" for c in range(len(cats)) if counts[c] < 10]
need = 200 if model != "grm" else 500
assumptions = [
{"key": "unidimensionality", "label": "One underlying trait", "status": "info",
"detail": "Assumed by the model; check it with a one-factor analysis (exploratory factor analysis or CFA) of the items."},
{"key": "sample_size", "label": "Sample size", "status": "warn" if n < need else "pass",
"detail": f"{n} respondents for {npar} parameters" + (f" — {need} or more are usually recommended for the {model_label[0].lower() + model_label[1:]}." if n < need else ".")},
{"key": "categories", "label": "Category use", "status": "warn" if sparse else "pass",
"detail": "Fewer than 10 responses: " + "; ".join(sparse[:8]) + (" …" if len(sparse) > 8 else "") + "." if sparse else "Every category has at least 10 responses."},
{"key": "convergence", "label": "Convergence", "status": "pass" if fit["converged"] else "warn",
"detail": f"EM converged in {fit['iterations']} cycles." if fit["converged"] else f"EM stopped after {fit['iterations']} cycles without converging."},
*diag["assumptions"], # item fit (S-X², Holm-adjusted) and local independence (Q3 more than 0.2 above its average)
]
# %% Result
cols = [{"key": "item", "label": "Item", "type": "string"}, {"key": "a", "label": "Discrimination a", "type": "number"},
{"key": "se_a", "label": "SE", "type": "number"}]
for m in range(1, kmax):
cols += [{"key": f"b{m}", "label": "Difficulty b" if kmax == 2 else f"Threshold b{m}", "type": "number"},
{"key": f"se_b{m}", "label": "SE", "type": "number"}]
theta = np.round(np.arange(-40, 41) / 10, 10)
info = ms.irt_information(fit, theta)
curve_t, curve_p, curve_i, curve_c = [], [], [], []
for (a, d), it, cats in zip(fit["params"], items, categories):
P = ms.category_probs(a, d, theta)
shown = [len(cats) - 1] if len(cats) == 2 else range(len(cats))
for c in shown:
curve_t += theta.tolist()
curve_p += P[:, c].tolist()
curve_i += [it] * len(theta)
curve_c += [cats[c]] * len(theta)
total = info.sum(axis=0)
charts = [
cs.chart("curves", "item-curves", "Item characteristic curves" if binary else "Category response curves", {
"theta": cs.col("Trait (θ)", curve_t, "numeric"),
"probability": cs.col("Probability", curve_p, "numeric"),
"item": cs.col("Item", curve_i, "categorical", levels=items),
**({} if binary else {"category": cs.col("Category", curve_c, "categorical")}),
}, controls={"kind": "icc"}),
cs.chart("information", "test-information", "Test information", {
"theta": cs.col("Trait (θ)", theta.tolist(), "numeric"),
"information": cs.col("Information", total.tolist(), "numeric"),
"se": cs.col("Standard error", (1 / np.sqrt(total)).tolist(), "numeric"),
}),
]
q3 = diag["q3"]
cells = [(i, j) for i in range(len(items)) for j in range(len(items))]
show = lambda i, j: i != j and np.isfinite(q3[i, j]) # noqa: E731
charts.append(cs.chart("q3", "matrix-heatmap", "Residual correlations (Q3)", {
"row": cs.col("Item", [items[i] for i, _ in cells], "categorical", levels=items),
"col": cs.col("With", [items[j] for _, j in cells], "categorical", levels=items),
"value": cs.col("Q3", [float(q3[i, j]) if show(i, j) else 0.0 for i, j in cells], "numeric"),
"label": cs.col("Text", [f"{q3[i, j]:.2f}" if show(i, j) else "" for i, j in cells], "categorical"),
}, controls={"scale": "diverging"}))
cs.publish({
"method": "measurement.irt",
"methodVersion": "1.1.0",
"title": model_label,
"engine": cs.engine_info("numpy", "scipy", "codesplash"),
"n": int(n),
"summary": f"{model_label} for {len(items)} items and {n} respondents: log-likelihood {loglik:.2f}, empirical reliability {reliability:.2f}.",
"apa": f"{model_label}: log-likelihood = {cs.fmt_num(loglik)}, AIC = {cs.fmt_num(values['aic'], 1)}, BIC = {cs.fmt_num(values['bic'], 1)}",
"statistics": [{"key": "loglik", "label": "Log-likelihood", "value": loglik}, {"key": "aic", "label": "AIC", "value": values["aic"]},
{"key": "bic", "label": "BIC", "value": values["bic"]}, {"key": "reliability", "label": "Empirical reliability", "value": reliability}],
"tables": [{"key": "items", "title": "Item parameters (IRT form: logit = a(θ − b))", "columns": cols, "rows": rows},
{"key": "persons", "title": "Person scores (EAP)", "columns": [{"key": "stat", "label": "", "type": "string"}, {"key": "value", "label": "Value", "type": "number"}],
"rows": [{"stat": "Mean", "value": float(eap.mean())}, {"stat": "SD", "value": float(np.sqrt(var_eap))},
{"stat": "Mean posterior SD", "value": float(np.sqrt(np.mean(psd**2)))}, {"stat": "Empirical reliability", "value": reliability}]},
*diag["tables"]],
"assumptions": assumptions,
"warnings": warnings,
"notes": [f"Marginal maximum likelihood (EM over 61 points on [−6, 6], θ ~ N(0, 1)); standard errors from the observed information; "
f"{fit['iterations']} EM cycles. Categories: " + "; ".join(f"{it}: {', '.join(c)}" for it, c in zip(items, categories))[:600],
*diag["notes"]],
"charts": charts,
"values": values,
})
The 2PL has the lower AIC (5,338 against 5,342 for Rasch), but Rasch has the lower BIC (5,371 against 5,387). The criteria disagree, which is common. The absolute fit statistic M2 helps: its p-value is 0.036 for 2PL and 0.006 for Rasch, so neither fits perfectly and 2PL fits less badly.
IRT for model benchmarks
ReadIRT is increasingly used on AI benchmarks: systems are the respondents, items the questions. It can show which items separate strong systems and which are noise. Cautions:
- The respondent population is small and related. A few dozen systems sharing training data violate the usual sampling picture.
- Contamination looks like ability. A system that saw the items scores high for the wrong reason.
- Missing isn't wrong. Treating unanswered or not-reached items as incorrect changes the model.
- Unidimensionality and local independence are assumptions: items sharing a passage, or a skill that only some items need, break them.
Raters as a facet
ReadRatings add a source of variation: who scored. The many-facet Rasch modelMany-facet Rasch modelA Rasch model where a rating depends on the person's ability, the rater's severity and the task's difficulty, all in logits on one scale. puts persons, items (tasks), raters and the rating scale's thresholds on one logit scale:
is rater 's severity. A person scored by a harsh rater gets credit for it. With , , and the reference's thresholds, the four category probabilities are 0.088, 0.264, 0.356 and 0.292.
Reference · HME009 · Runs in CodeSplashMany-facet Rasch measurement modelSeparate person or system performance, task difficulty, rater severity, and category thresholds in an additive ordinal measurement model.Predict: raters who never overlap
PredictPredict first
Rater A scored only class 1's essays and rater B only class 2's. Can a many-facet Rasch model tell whether A is harsher or class 1 is weaker?
Reveal
No. Without linking (shared essays, shared tasks or anchor items), a lower average could be a harsher rater or weaker writers, and the data can't say which. Design the rating plan so every rater overlaps with others.
Rater facets in CodeSplash
ReadMany-facet Rasch model (rater severity) reads persons, raters, optional tasks and an ordinal score.
Many-facet Rasch model (JML): rater fixed χ²(3) = 16.42, p < .001; rater separation reliability = .75
- Rater fixed χ²
- 16.418
- p
- < .001
- Rater separation reliability
- 0.7510
Plots
View data
| Facet | Element | Measure (logits) |
|---|---|---|
| Persons | e01 | 2.233 |
| Persons | e02 | 0.5065 |
| Persons | e03 | 0.7616 |
| Persons | e04 | 1.380 |
| Persons | e05 | 0.1244 |
| Persons | e06 | −0.8463 |
| Persons | e07 | 0.7712 |
| Persons | e08 | −2.327 |
| Persons | e09 | 0.9109 |
| Persons | e10 | −0.2382 |
| Persons | e11 | −3.857 |
| Persons | e12 | −0.9394 |
| Persons | e13 | −0.4770 |
| Persons | e14 | 0.5065 |
| Persons | e15 | −0.3835 |
| Persons | e16 | 0.0301 |
| Persons | e17 | 0.3400 |
| Persons | e18 | −0.2906 |
| Persons | e19 | −1.368 |
| Persons | e20 | −0.2906 |
| Persons | e21 | 1.139 |
| Persons | e22 | −3.345 |
| Persons | e23 | 1.144 |
| Persons | e24 | −1.977 |
| Persons | e25 | 0.6468 |
| Persons | e26 | 1.596 |
| Persons | e27 | 0.9734 |
| Persons | e28 | 1.139 |
| Persons | e29 | −2.409 |
| Persons | e30 | 1.277 |
| Persons | e31 | 1.486 |
| Persons | e32 | −0.8463 |
| Persons | e33 | −0.4386 |
| Persons | e34 | 1.093 |
| Persons | e35 | −2.018 |
| Persons | e36 | 1.892 |
| Persons | e37 | −0.2382 |
| Persons | e38 | 2.924 |
| Persons | e39 | 0.1041 |
| Persons | e40 | 1.641 |
| Raters | r1 | −0.5429 |
| Raters | r2 | 0.2134 |
| Raters | r3 | 0.0316 |
| Raters | r4 | 0.2979 |
| Items | argument | −0.4775 |
| Items | evidence | 0.1389 |
| Items | style | 0.3386 |
| Thresholds | 2 | −2.259 |
| Thresholds | 3 | −0.3407 |
| Thresholds | 4 | 0.8937 |
| Thresholds | 5 | 1.706 |
View data
| Severity (logits) | High | Rater | Low |
|---|---|---|---|
| −0.5429 | −0.2262 | r1 | −0.8596 |
| 0.2134 | 0.5444 | r2 | −0.1177 |
| 0.0316 | 0.3541 | r3 | −0.2908 |
| 0.2979 | 0.6102 | r4 | −0.0143 |
View data
| Score | Scale | Probability | Measure relative to the rating (logits) |
|---|---|---|---|
| 1 | Scale | 0.9767 | −6 |
| 1 | Scale | 0.9744 | −5.900 |
| 1 | Scale | 0.9717 | −5.800 |
| 1 | Scale | 0.9688 | −5.700 |
| 1 | Scale | 0.9656 | −5.600 |
| 1 | Scale | 0.9621 | −5.500 |
| 1 | Scale | 0.9583 | −5.400 |
| 1 | Scale | 0.9541 | −5.300 |
| 1 | Scale | 0.9495 | −5.200 |
| 1 | Scale | 0.9444 | −5.100 |
| 1 | Scale | 0.9389 | −5 |
| 1 | Scale | 0.9328 | −4.900 |
| 1 | Scale | 0.9262 | −4.800 |
| 1 | Scale | 0.9190 | −4.700 |
| 1 | Scale | 0.9111 | −4.600 |
| 1 | Scale | 0.9025 | −4.500 |
| 1 | Scale | 0.8932 | −4.400 |
| 1 | Scale | 0.8831 | −4.300 |
| 1 | Scale | 0.8722 | −4.200 |
| 1 | Scale | 0.8603 | −4.100 |
| 1 | Scale | 0.8476 | −4 |
| 1 | Scale | 0.8338 | −3.900 |
| 1 | Scale | 0.8190 | −3.800 |
| 1 | Scale | 0.8032 | −3.700 |
| 1 | Scale | 0.7863 | −3.600 |
| 1 | Scale | 0.7684 | −3.500 |
| 1 | Scale | 0.7493 | −3.400 |
| 1 | Scale | 0.7291 | −3.300 |
| 1 | Scale | 0.7078 | −3.200 |
| 1 | Scale | 0.6854 | −3.100 |
| 1 | Scale | 0.6620 | −3 |
| 1 | Scale | 0.6376 | −2.900 |
| 1 | Scale | 0.6123 | −2.800 |
| 1 | Scale | 0.5862 | −2.700 |
| 1 | Scale | 0.5594 | −2.600 |
| 1 | Scale | 0.5321 | −2.500 |
| 1 | Scale | 0.5042 | −2.400 |
| 1 | Scale | 0.4761 | −2.300 |
| 1 | Scale | 0.4477 | −2.200 |
| 1 | Scale | 0.4194 | −2.100 |
| 1 | Scale | 0.3913 | −2 |
| 1 | Scale | 0.3634 | −1.900 |
| 1 | Scale | 0.3361 | −1.800 |
| 1 | Scale | 0.3094 | −1.700 |
| 1 | Scale | 0.2834 | −1.600 |
| 1 | Scale | 0.2584 | −1.500 |
| 1 | Scale | 0.2345 | −1.400 |
| 1 | Scale | 0.2116 | −1.300 |
| 1 | Scale | 0.1900 | −1.200 |
| 1 | Scale | 0.1697 | −1.100 |
| 1 | Scale | 0.1507 | −1 |
| 1 | Scale | 0.1331 | −0.9000 |
| 1 | Scale | 0.1168 | −0.8000 |
| 1 | Scale | 0.1020 | −0.7000 |
| 1 | Scale | 0.0884 | −0.6000 |
| 1 | Scale | 0.0762 | −0.5000 |
| 1 | Scale | 0.0653 | −0.4000 |
| 1 | Scale | 0.0555 | −0.3000 |
| 1 | Scale | 0.0469 | −0.2000 |
| 1 | Scale | 0.0393 | −0.1000 |
First 60 of 605 rows.
Assumptions
- Rater fit — Every rater's infit and outfit mean squares are within 0.5–1.5.
- Unexpected ratings — 4.6% of ratings have |z| > 2 and 0.0% have |z| > 3 (about 5% and 1% expected).
- Category use — Every score category has at least 10 ratings.
- Extreme scores — 1 person(s) with the lowest or highest score in every rating were set aside (no finite estimate).
- Convergence — Newton–Raphson converged after 8 iterations.
Raters (higher = more severe)
| Rater | Measure (logits) | SE | Infit MnSq | Outfit MnSq | Ratings | Mean score (category) | Extreme |
|---|---|---|---|---|---|---|---|
| r1 | −0.5429 | 0.1616 | 0.8321 | 0.8419 | 60 | 2.483 | |
| r2 | 0.2134 | 0.1689 | 1.037 | 1.087 | 60 | 1.783 | |
| r3 | 0.0316 | 0.1645 | 0.8057 | 0.8129 | 60 | 1.983 | |
| r4 | 0.2979 | 0.1593 | 1.272 | 1.273 | 60 | 1.850 |
Items (higher = harder)
| Item | Measure (logits) | SE | Infit MnSq | Outfit MnSq | Ratings | Mean score (category) | Extreme |
|---|---|---|---|---|---|---|---|
| argument | −0.4775 | 0.1420 | 1.270 | 1.218 | 80 | 2.325 | |
| evidence | 0.1389 | 0.1409 | 0.9427 | 0.9913 | 80 | 1.938 | |
| style | 0.3386 | 0.1418 | 0.7573 | 0.8018 | 80 | 1.813 |
Persons (higher = more able)
| Person | Measure (logits) | SE | Infit MnSq | Outfit MnSq | Ratings | Mean score (category) | Extreme |
|---|---|---|---|---|---|---|---|
| e01 | 2.233 | 0.6252 | 0.3194 | 0.3599 | 6 | 3.500 | |
| e02 | 0.5065 | 0.4636 | 0.3079 | 0.3081 | 6 | 2.167 | |
| e03 | 0.7616 | 0.4605 | 0.4057 | 0.4096 | 6 | 2.333 | |
| e04 | 1.380 | 0.4994 | 1.003 | 0.9085 | 6 | 3 | |
| e05 | 0.1244 | 0.4661 | 0.2793 | 0.2737 | 6 | 2.167 | |
| e06 | −0.8463 | 0.5472 | 0.8016 | 0.8405 | 6 | 1.167 | |
| e07 | 0.7712 | 0.4683 | 0.6921 | 0.6729 | 6 | 2.667 | |
| e08 | −2.327 | 0.6980 | 0.7606 | 0.7770 | 6 | 0.5000 | |
| e09 | 0.9109 | 0.4731 | 0.4097 | 0.4289 | 6 | 2.667 | |
| e10 | −0.2382 | 0.4830 | 0.6033 | 0.5954 | 6 | 1.833 | |
| e11 | −3.857 | 1.069 | 1.058 | 1.238 | 6 | 0.1667 | |
| e12 | −0.9394 | 0.5473 | 0.9604 | 0.9909 | 6 | 1.167 | |
| e13 | −0.4770 | 0.4948 | 1.734 | 1.724 | 6 | 1.667 | |
| e14 | 0.5065 | 0.4636 | 1.101 | 1.094 | 6 | 2.167 | |
| e15 | −0.3835 | 0.5087 | 2.145 | 2.034 | 6 | 1.500 | |
| e16 | 0.0301 | 0.4749 | 0.4541 | 0.4448 | 6 | 2 | |
| e17 | 0.3400 | 0.4631 | 1.319 | 1.318 | 6 | 2.333 | |
| e18 | −0.2906 | 0.5086 | 1.277 | 1.331 | 6 | 1.500 | |
| e19 | −1.368 | 0.5474 | 1.062 | 0.9459 | 6 | 1.167 | |
| e20 | −0.2906 | 0.5086 | 2.765 | 2.579 | 6 | 1.500 | |
| e21 | 1.139 | 0.4831 | 0.7660 | 0.7492 | 6 | 2.833 | |
| e22 | −3.345 | 0.8117 | 0.8323 | 1.094 | 6 | 0.3333 | |
| e23 | 1.144 | 0.4645 | 1.043 | 1.050 | 6 | 2.667 | |
| e24 | −1.977 | 0.6392 | 0.7481 | 0.7259 | 6 | 0.6667 | |
| e25 | 0.6468 | 0.4664 | 1.829 | 1.864 | 6 | 2.500 | |
| e26 | 1.596 | 0.4898 | 0.5847 | 0.6023 | 6 | 3 | |
| e27 | 0.9734 | 0.4607 | 0.3859 | 0.3840 | 6 | 2.500 | |
| e28 | 1.139 | 0.4831 | 1.561 | 1.703 | 6 | 2.833 | |
| e29 | −2.409 | 0.6410 | 1.244 | 1.236 | 6 | 0.6667 | |
| e30 | 1.277 | 0.4642 | 0.9694 | 0.9844 | 6 | 2.667 | |
| e31 | 1.486 | 0.5193 | 0.6747 | 0.7495 | 6 | 3.167 | |
| e32 | −0.8463 | 0.5472 | 0.8335 | 0.8694 | 6 | 1.167 | |
| e33 | −0.4386 | 0.4952 | 1.827 | 1.869 | 6 | 1.667 | |
| e34 | 1.093 | 0.4813 | 0.8460 | 0.8539 | 6 | 2.833 | |
| e35 | −2.018 | 0.6390 | 1.691 | 1.649 | 6 | 0.6667 | |
| e36 | 1.892 | 0.5156 | 0.9065 | 0.8890 | 6 | 3.167 | |
| e37 | −0.2382 | 0.4830 | 1.397 | 1.332 | 6 | 1.833 | |
| e38 | 2.924 | 0.7357 | 0.8063 | 0.8943 | 6 | 3.667 | |
| e39 | 0.1041 | 0.4805 | 0.7260 | 0.7112 | 6 | 1.833 | |
| e40 | 1.641 | 0.5246 | 0.6107 | 0.6705 | 6 | 3.167 |
First 40 of 41 rows.
Rasch–Andrich thresholds
| Scale | Step up to score | Threshold (logits) |
|---|---|---|
| Scale | 2 | −2.259 |
| Scale | 3 | −0.3407 |
| Scale | 4 | 0.8937 |
| Scale | 5 | 1.706 |
Separation and reliability
| Facet | SD of measures | RMSE | Separation | Reliability | Fixed χ² (all same) | df | p |
|---|---|---|---|---|---|---|---|
| Persons | 1.478 | 0.5525 | 2.481 | 0.8603 | 207.11 | 39 | < .001 |
| Raters | 0.3279 | 0.1636 | 1.737 | 0.7510 | 16.418 | 3 | < .001 |
| Items | 0.3473 | 0.1416 | 2.241 | 0.8339 | 17.984 | 2 | < .001 |
- Joint maximum likelihood (as in Facets): rater severities and item difficulties centered at 0, thresholds centered within each scale; local model SEs (1/√information). JML measures are slightly spread out when an element has few ratings.
The exact R script · R R version 4.5.1 (2025-06-13)
# Many-facet Rasch model (rater severity)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method measurement.facets 1.0.0 · spec 5ce1e84cfc6bbf10
# Dataset: facets_sim (version 1)
# Runs on its own: outside the app, cs_publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
library(codesplashr)
# %% Data
df <- as.data.frame(nanoparquet::read_parquet("tests/parity/fixtures/facets_sim.parquet", col_select = c("essay", "rater", "task", "score")))
n_input <- nrow(df)
df[["essay"]] <- factor(df[["essay"]], levels = c("e01", "e02", "e03", "e04", "e05", "e06", "e07", "e08", "e09", "e10", "e11", "e12", "e13", "e14", "e15", "e16", "e17", "e18", "e19", "e20", "e21", "e22", "e23", "e24", "e25", "e26", "e27", "e28", "e29", "e30", "e31", "e32", "e33", "e34", "e35", "e36", "e37", "e38", "e39", "e40", "e41")) # stored level order
df[["rater"]] <- factor(df[["rater"]], levels = c("r1", "r2", "r3", "r4")) # stored level order
df[["task"]] <- factor(df[["task"]], levels = c("argument", "evidence", "style")) # stored level order
df <- df[stats::complete.cases(df[c("essay", "rater", "task", "score")]), , drop = FALSE] # listwise deletion
df[] <- lapply(df, function(x) if (is.factor(x)) droplevels(x) else x)
n_dropped <- n_input - nrow(df)
warnings <- list()
if (n_dropped > 0) {
warnings <- c(warnings, cs_warning("CS_W_ROWS_DROPPED", dropped = n_dropped, total = n_input))
}
if (n_input > 0 && nrow(df) == 0) cs_error("CS_E_NO_ROWS")
cs_check_finite_columns(df, c("essay", "rater", "task", "score")) # infinite values stop the run (registry/errors.yaml)
# %% Facets and score categories
person_col <- "essay"
rater_col <- "rater"
score_col <- "score"
item_col <- "task"
persons <- levels(df[[person_col]])
raters <- levels(df[[rater_col]])
items <- if (!is.null(item_col)) levels(df[[item_col]]) else "All"
note_gaps <- ""
if (is.factor(df[[score_col]])) {
cats <- levels(df[[score_col]])
x <- as.integer(df[[score_col]]) - 1L
} else {
v <- as.numeric(df[[score_col]])
bad <- sum(v != round(v))
if (bad) cs_error("CS_E_INVALID_VALUES", column = score_col, requirement = "whole numbers (ordered score categories)", count = bad)
vals <- sort(unique(v))
if (length(vals) > 15) cs_error("CS_E_TOO_MANY_LEVELS", column = score_col, k = length(vals), max = 15)
cats <- as.character(as.integer(vals))
x <- match(v, vals) - 1L
if (length(vals) >= 2 && vals[length(vals)] - vals[1] + 1 > length(vals))
note_gaps <- sprintf(" Unused score values between %s and %s were skipped: the categories are the %d values used.", cats[1], cats[length(cats)], length(vals))
}
k <- length(cats)
if (k < 2) cs_error("CS_E_TOO_FEW_GROUPS", column = score_col, min = 2, k = k)
if (k > 15) cs_error("CS_E_TOO_MANY_LEVELS", column = score_col, k = k, max = 15)
n_p <- length(persons)
n_r <- length(raters)
n_i <- length(items)
if (n_p < 2) cs_error("CS_E_TOO_FEW_GROUPS", column = person_col, min = 2, k = n_p)
if (n_r < 2) cs_error("CS_E_TOO_FEW_GROUPS", column = rater_col, min = 2, k = n_r)
m <- k - 1L
person <- as.integer(df[[person_col]])
rater <- as.integer(df[[rater_col]])
item <- if (!is.null(item_col)) as.integer(df[[item_col]]) else rep(1L, nrow(df))
thresholds <- "shared"
if (thresholds == "by_item" && is.null(item_col)) thresholds <- "shared"
if (thresholds == "by_item") {
groups <- item
group_names <- items
} else if (thresholds == "by_rater") {
groups <- rater
group_names <- raters
} else {
groups <- rep(1L, nrow(df))
group_names <- "Scale"
}
n_g <- length(group_names)
# %% Extreme scores and linkage
ex <- cs_facets_extremes(person, rater, item, x, n_p, n_r, n_i, m)
active <- ex$active
flags <- ex$flags
if (!any(active)) cs_error("CS_E_UNDEFINED", what = "Many-facet Rasch measures", reason = "every person has the lowest or highest score in every rating")
subsets <- cs_facets_connected(person[active], rater[active], item[active], n_p, n_r, n_i)
if (subsets > 1) cs_error("CS_E_UNDEFINED", what = "Many-facet Rasch measures",
reason = sprintf("the ratings split into %d groups that share no raters, persons or items, so their measures can't be compared; link them with shared raters", subsets))
for (g in sort(unique(groups[active]))) {
used <- unique(x[active & groups == g])
if (length(used) < k) {
miss <- cats[!(seq_len(k) - 1L) %in% used]
where <- if (thresholds == "shared") "" else sprintf(" for %s", group_names[g])
cs_error("CS_E_UNDEFINED", what = "The rating-scale thresholds",
reason = sprintf("score %s is never given%s once extreme scores are set aside; use shared thresholds or merge categories", paste(miss, collapse = ", "), where))
}
}
# %% Fit (joint maximum likelihood)
xa <- x[active]
fit <- cs_facets_fit(person[active], rater[active], item[active], xa, n_p, n_r, n_i, m, groups[active], n_g)
E <- fit$expected
V <- fit$variance
z <- (xa - E) / sqrt(V)
st_p <- cs_facets_element_stats(person[active], n_p, xa, E, V)
st_r <- cs_facets_element_stats(rater[active], n_r, xa, E, V)
st_i <- cs_facets_element_stats(item[active], n_i, xa, E, V)
sep_p <- cs_facets_separation(fit$theta, st_p$se)
sep_r <- cs_facets_separation(fit$alpha, st_r$se)
sep_i <- if (!is.null(item_col)) cs_facets_separation(fit$beta, st_i$se) else NULL
fin <- function(v) if (is.null(v) || length(v) == 0 || !is.finite(v)) NA_real_ else unname(v)
thr_label <- c(shared = "one rating scale", by_item = "a scale per item", by_rater = "a scale per rater")[[thresholds]]
misfit <- raters[is.finite(st_r$infit) & !(st_r$infit >= 0.5 & st_r$infit <= 1.5 & st_r$outfit >= 0.5 & st_r$outfit <= 1.5)]
values <- list(
n_obs = length(x), n_used = sum(active), n_persons = n_p, n_raters = n_r, n_items = if (!is.null(item_col)) n_i else 0,
n_extreme = sum(flags[[1]] != 0), categories = k, loglik = fit$loglik, iterations = fit$iterations,
converged = if (fit$converged) 1 else 0,
sep_person = fin(sep_p$separation), rel_person = fin(sep_p$reliability),
sep_rater = fin(sep_r$separation), rel_rater = fin(sep_r$reliability),
rater_chisq = fin(sep_r$chisq), rater_df = fin(sep_r$df), rater_p = fin(sep_r$p),
severity_range = max(fit$alpha, na.rm = TRUE) - min(fit$alpha, na.rm = TRUE),
share_z2 = mean(abs(z) > 2), share_z3 = mean(abs(z) > 3),
rater_misfit = length(misfit), thresholds_label = thr_label
)
values[c("sep_item", "rel_item", "item_chisq", "item_df", "item_p")] <- list(NA_real_) # no task facet: empty
if (!is.null(item_col)) {
values$sep_item <- fin(sep_i$separation)
values$rel_item <- fin(sep_i$reliability)
values$item_chisq <- fin(sep_i$chisq)
values$item_df <- fin(sep_i$df)
values$item_p <- fin(sep_i$p)
}
for (j in seq_len(n_r)) {
r <- raters[j]
values[[sprintf("severity[%s]", r)]] <- fin(fit$alpha[j])
values[[sprintf("se_severity[%s]", r)]] <- fin(st_r$se[j])
values[[sprintf("infit[%s]", r)]] <- fin(st_r$infit[j])
values[[sprintf("outfit[%s]", r)]] <- fin(st_r$outfit[j])
}
if (!is.null(item_col)) {
for (i in seq_len(n_i)) {
values[[sprintf("difficulty[%s]", items[i])]] <- fin(fit$beta[i])
values[[sprintf("se_difficulty[%s]", items[i])]] <- fin(st_i$se[i])
}
}
tau <- fit$tau
for (g in seq_len(n_g)) {
for (h in seq_len(m)) {
key <- if (thresholds == "shared") sprintf("threshold[%s]", cats[h + 1]) else sprintf("threshold[%s|%s]", group_names[g], cats[h + 1])
values[[key]] <- tau[g, h]
}
}
# %% Assumptions
counts <- tabulate(xa + 1L, k)
rare <- cats[counts < 10]
pct1 <- function(v) sprintf("%.1f%%", 100 * v)
assumptions <- list(
list(key = "rater_fit", label = "Rater fit", status = if (length(misfit)) "warn" else "pass",
detail = if (length(misfit)) sprintf("Infit or outfit outside 0.5–1.5: %s.", paste(misfit, collapse = ", ")) else "Every rater's infit and outfit mean squares are within 0.5–1.5."),
list(key = "residuals", label = "Unexpected ratings", status = if (values$share_z2 > 0.05 || values$share_z3 > 0.01) "warn" else "pass",
detail = sprintf("%s of ratings have |z| > 2 and %s have |z| > 3 (about 5%% and 1%% expected).", pct1(values$share_z2), pct1(values$share_z3))),
list(key = "category_use", label = "Category use", status = if (length(rare)) "warn" else "pass",
detail = if (length(rare)) sprintf("Fewer than 10 ratings in: %s.", paste(rare, collapse = ", ")) else "Every score category has at least 10 ratings."),
list(key = "extremes", label = "Extreme scores", status = "info",
detail = if (values$n_extreme > 0) sprintf("%d person(s) with the lowest or highest score in every rating were set aside (no finite estimate).", as.integer(values$n_extreme)) else "No person has an extreme score."),
list(key = "convergence", label = "Convergence", status = if (fit$converged) "pass" else "warn",
detail = sprintf("Newton–Raphson %s after %d iterations.", if (fit$converged) "converged" else "stopped before converging", fit$iterations))
)
if (!fit$converged) warnings <- c(warnings, cs_warning("CS_W_NO_CONVERGENCE", what = "Many-facet Rasch"))
# %% Tables
facet_rows <- function(names, meas, st, flg) {
lapply(seq_along(names), function(e) list(element = names[e], measure = fin(meas[e]), se = fin(st$se[e]), infit = fin(st$infit[e]),
outfit = fin(st$outfit[e]), count = as.integer(st$count[e]), observed = fin(st$observed[e]),
status = if (flg[e] < 0) "lowest score" else if (flg[e] > 0) "highest score" else ""))
}
fcols <- function(what) list(
list(key = "element", label = what, type = "string"), list(key = "measure", label = "Measure (logits)", type = "number"),
list(key = "se", label = "SE", type = "number"), list(key = "infit", label = "Infit MnSq", type = "number"),
list(key = "outfit", label = "Outfit MnSq", type = "number"), list(key = "count", label = "Ratings", type = "integer"),
list(key = "observed", label = "Mean score (category)", type = "number"), list(key = "status", label = "Extreme", type = "string"))
tables <- list(list(key = "raters", title = "Raters (higher = more severe)", columns = fcols("Rater"), rows = facet_rows(raters, fit$alpha, st_r, flags[[2]])))
if (!is.null(item_col)) tables[[length(tables) + 1]] <- list(key = "items", title = "Items (higher = harder)", columns = fcols("Item"),
rows = facet_rows(items, fit$beta, st_i, flags[[3]]))
tables[[length(tables) + 1]] <- list(key = "persons", title = "Persons (higher = more able)", columns = fcols("Person"),
rows = facet_rows(persons, fit$theta, st_p, flags[[1]]))
thr_rows <- list()
for (g in seq_len(n_g)) for (h in seq_len(m)) thr_rows[[length(thr_rows) + 1]] <- list(scale = group_names[g], category = cats[h + 1], threshold = tau[g, h])
tables[[length(tables) + 1]] <- list(key = "thresholds", title = "Rasch–Andrich thresholds", columns = list(
list(key = "scale", label = "Scale", type = "string"), list(key = "category", label = "Step up to score", type = "string"),
list(key = "threshold", label = "Threshold (logits)", type = "number")), rows = thr_rows)
sep_row <- function(name, s) c(list(facet = name), lapply(s[c("sd", "rmse", "separation", "reliability", "chisq", "df", "p")], fin))
sep_rows <- list(sep_row("Persons", sep_p), sep_row("Raters", sep_r))
if (!is.null(item_col)) sep_rows[[3]] <- sep_row("Items", sep_i)
tables[[length(tables) + 1]] <- list(key = "separation", title = "Separation and reliability", columns = list(
list(key = "facet", label = "Facet", type = "string"), list(key = "sd", label = "SD of measures", type = "number"),
list(key = "rmse", label = "RMSE", type = "number"), list(key = "separation", label = "Separation", type = "number"),
list(key = "reliability", label = "Reliability", type = "number"), list(key = "chisq", label = "Fixed χ² (all same)", type = "number"),
list(key = "df", label = "df", type = "integer"), list(key = "p", label = "p", type = "pvalue")), rows = sep_rows)
# %% Charts
facet_order <- c("Persons", "Raters", if (!is.null(item_col)) "Items", "Thresholds")
parts <- list(list("Persons", fit$theta, persons), list("Raters", fit$alpha, raters))
if (!is.null(item_col)) parts[[3]] <- list("Items", fit$beta, items)
wm_f <- character(0)
wm_m <- numeric(0)
wm_l <- character(0)
for (pp in parts) {
ok <- is.finite(pp[[2]])
wm_f <- c(wm_f, rep(pp[[1]], sum(ok)))
wm_m <- c(wm_m, pp[[2]][ok])
wm_l <- c(wm_l, pp[[3]][ok])
}
for (g in seq_len(n_g)) for (h in seq_len(m)) {
wm_f <- c(wm_f, "Thresholds")
wm_m <- c(wm_m, tau[g, h])
wm_l <- c(wm_l, if (thresholds == "shared") cats[h + 1] else paste(group_names[g], cats[h + 1]))
}
ra <- is.finite(fit$alpha)
charts <- list(
cs_chart("wright", "wright-map", paste0("Wright map: persons, raters", if (!is.null(item_col)) ", items" else "", " and thresholds on one logit scale"), list(
facet = cs_col("Facet", wm_f, "categorical", levels = facet_order),
measure = cs_col("Measure (logits)", wm_m, "numeric"),
label = cs_col("Element", wm_l, "categorical")
)),
cs_chart("severity", "forest", "Rater severity (±1.96 SE)", list(
label = cs_col("Rater", raters[ra], "categorical", levels = raters[ra]),
estimate = cs_col("Severity (logits)", fit$alpha[ra], "numeric"),
low = cs_col("Low", fit$alpha[ra] - 1.96 * st_r$se[ra], "numeric"),
high = cs_col("High", fit$alpha[ra] + 1.96 * st_r$se[ra], "numeric")
), controls = list(reference = 0))
)
grid <- seq(-6, 6, length.out = 121)
cur_t <- numeric(0)
cur_p <- numeric(0)
cur_s <- character(0)
cur_c <- character(0)
for (g in seq_len(n_g)) {
cum <- c(0, cumsum(tau[g, ]))
s <- outer(grid, 0:(k - 1)) - matrix(cum, length(grid), k, byrow = TRUE)
P <- exp(s - apply(s, 1, max))
P <- P / rowSums(P)
for (c0 in seq_len(k)) {
cur_t <- c(cur_t, grid)
cur_p <- c(cur_p, P[, c0])
cur_s <- c(cur_s, rep(group_names[g], length(grid)))
cur_c <- c(cur_c, rep(cats[c0], length(grid)))
}
}
charts[[3]] <- cs_chart("categories", "item-curves", "Category probability curves", list(
theta = cs_col("Measure relative to the rating (logits)", cur_t, "numeric"),
probability = cs_col("Probability", cur_p, "numeric"),
item = cs_col("Scale", cur_s, "categorical", levels = group_names),
category = cs_col("Score", cur_c, "categorical", levels = cats)
), controls = list(kind = "icc"))
# %% Result
cs_publish(list(
method = "measurement.facets",
methodVersion = "1.0.0",
title = "Many-facet Rasch model",
engine = cs_engine_info("stats", "codesplashr"),
n = sum(active),
summary = sprintf("Many-facet Rasch model (%s) for %d ratings by %d raters: rater severities span %.2f logits; rater separation reliability %.2f, person reliability %.2f.",
thr_label, sum(active), n_r, values$severity_range, values$rel_rater, values$rel_person),
apa = sprintf("Many-facet Rasch model (JML): rater fixed χ²(%d) = %s, %s; rater separation reliability = %s", as.integer(sep_r$df),
cs_fmt_num(sep_r$chisq, 2), cs_fmt_p(sep_r$p), cs_fmt_num(sep_r$reliability, 2, leading_zero = FALSE)),
statistics = list(list(key = "rater_chisq", label = "Rater fixed χ²", value = values$rater_chisq),
list(key = "rater_p", label = "p", value = values$rater_p, format = "p"),
list(key = "rel_rater", label = "Rater separation reliability", value = values$rel_rater)),
tables = tables,
assumptions = assumptions,
warnings = warnings,
notes = list(sprintf("Joint maximum likelihood (as in Facets): rater severities%s centered at 0, thresholds centered within each scale; local model SEs (1/√information). JML measures are slightly spread out when an element has few ratings.%s",
if (!is.null(item_col)) " and item difficulties" else "", note_gaps)),
charts = charts,
values = values
))
Many-facet Rasch model (JML): rater fixed χ²(3) = 16.42, p < .001; rater separation reliability = .75
- Rater fixed χ²
- 16.418
- p
- < .001
- Rater separation reliability
- 0.7510
To keep this page light, the plots are shown once, under the R tab.
Assumptions
- Rater fit — Every rater's infit and outfit mean squares are within 0.5–1.5.
- Unexpected ratings — 4.6% of ratings have |z| > 2 and 0.0% have |z| > 3 (about 5% and 1% expected).
- Category use — Every score category has at least 10 ratings.
- Extreme scores — 1 person(s) with the lowest or highest score in every rating were set aside (no finite estimate).
- Convergence — Newton–Raphson converged after 8 iterations.
Raters (higher = more severe)
| Rater | Measure (logits) | SE | Infit MnSq | Outfit MnSq | Ratings | Mean score (category) | Extreme |
|---|---|---|---|---|---|---|---|
| r1 | −0.5429 | 0.1616 | 0.8321 | 0.8419 | 60 | 2.483 | |
| r2 | 0.2134 | 0.1689 | 1.037 | 1.087 | 60 | 1.783 | |
| r3 | 0.0316 | 0.1645 | 0.8057 | 0.8129 | 60 | 1.983 | |
| r4 | 0.2979 | 0.1593 | 1.272 | 1.273 | 60 | 1.850 |
Items (higher = harder)
| Item | Measure (logits) | SE | Infit MnSq | Outfit MnSq | Ratings | Mean score (category) | Extreme |
|---|---|---|---|---|---|---|---|
| argument | −0.4775 | 0.1420 | 1.270 | 1.218 | 80 | 2.325 | |
| evidence | 0.1389 | 0.1409 | 0.9427 | 0.9913 | 80 | 1.938 | |
| style | 0.3386 | 0.1418 | 0.7573 | 0.8018 | 80 | 1.813 |
Persons (higher = more able)
| Person | Measure (logits) | SE | Infit MnSq | Outfit MnSq | Ratings | Mean score (category) | Extreme |
|---|---|---|---|---|---|---|---|
| e01 | 2.233 | 0.6252 | 0.3194 | 0.3599 | 6 | 3.500 | |
| e02 | 0.5065 | 0.4636 | 0.3079 | 0.3081 | 6 | 2.167 | |
| e03 | 0.7616 | 0.4605 | 0.4057 | 0.4096 | 6 | 2.333 | |
| e04 | 1.380 | 0.4994 | 1.003 | 0.9085 | 6 | 3 | |
| e05 | 0.1244 | 0.4661 | 0.2793 | 0.2737 | 6 | 2.167 | |
| e06 | −0.8463 | 0.5472 | 0.8016 | 0.8405 | 6 | 1.167 | |
| e07 | 0.7712 | 0.4683 | 0.6921 | 0.6729 | 6 | 2.667 | |
| e08 | −2.327 | 0.6980 | 0.7606 | 0.7770 | 6 | 0.5000 | |
| e09 | 0.9109 | 0.4731 | 0.4097 | 0.4289 | 6 | 2.667 | |
| e10 | −0.2382 | 0.4830 | 0.6033 | 0.5954 | 6 | 1.833 | |
| e11 | −3.857 | 1.069 | 1.058 | 1.238 | 6 | 0.1667 | |
| e12 | −0.9394 | 0.5473 | 0.9604 | 0.9909 | 6 | 1.167 | |
| e13 | −0.4770 | 0.4948 | 1.734 | 1.724 | 6 | 1.667 | |
| e14 | 0.5065 | 0.4636 | 1.101 | 1.094 | 6 | 2.167 | |
| e15 | −0.3835 | 0.5087 | 2.145 | 2.034 | 6 | 1.500 | |
| e16 | 0.0301 | 0.4749 | 0.4541 | 0.4448 | 6 | 2 | |
| e17 | 0.3400 | 0.4631 | 1.319 | 1.318 | 6 | 2.333 | |
| e18 | −0.2906 | 0.5086 | 1.277 | 1.331 | 6 | 1.500 | |
| e19 | −1.368 | 0.5474 | 1.062 | 0.9459 | 6 | 1.167 | |
| e20 | −0.2906 | 0.5086 | 2.765 | 2.579 | 6 | 1.500 | |
| e21 | 1.139 | 0.4831 | 0.7660 | 0.7492 | 6 | 2.833 | |
| e22 | −3.345 | 0.8117 | 0.8323 | 1.094 | 6 | 0.3333 | |
| e23 | 1.144 | 0.4645 | 1.043 | 1.050 | 6 | 2.667 | |
| e24 | −1.977 | 0.6392 | 0.7481 | 0.7259 | 6 | 0.6667 | |
| e25 | 0.6468 | 0.4664 | 1.829 | 1.864 | 6 | 2.500 | |
| e26 | 1.596 | 0.4898 | 0.5847 | 0.6023 | 6 | 3 | |
| e27 | 0.9734 | 0.4607 | 0.3859 | 0.3840 | 6 | 2.500 | |
| e28 | 1.139 | 0.4831 | 1.561 | 1.703 | 6 | 2.833 | |
| e29 | −2.409 | 0.6410 | 1.244 | 1.236 | 6 | 0.6667 | |
| e30 | 1.277 | 0.4642 | 0.9694 | 0.9844 | 6 | 2.667 | |
| e31 | 1.486 | 0.5193 | 0.6747 | 0.7495 | 6 | 3.167 | |
| e32 | −0.8463 | 0.5472 | 0.8335 | 0.8694 | 6 | 1.167 | |
| e33 | −0.4386 | 0.4952 | 1.827 | 1.869 | 6 | 1.667 | |
| e34 | 1.093 | 0.4813 | 0.8460 | 0.8539 | 6 | 2.833 | |
| e35 | −2.018 | 0.6390 | 1.691 | 1.649 | 6 | 0.6667 | |
| e36 | 1.892 | 0.5156 | 0.9065 | 0.8890 | 6 | 3.167 | |
| e37 | −0.2382 | 0.4830 | 1.397 | 1.332 | 6 | 1.833 | |
| e38 | 2.924 | 0.7357 | 0.8063 | 0.8943 | 6 | 3.667 | |
| e39 | 0.1041 | 0.4805 | 0.7260 | 0.7112 | 6 | 1.833 | |
| e40 | 1.641 | 0.5246 | 0.6107 | 0.6705 | 6 | 3.167 |
First 40 of 41 rows.
Rasch–Andrich thresholds
| Scale | Step up to score | Threshold (logits) |
|---|---|---|
| Scale | 2 | −2.259 |
| Scale | 3 | −0.3407 |
| Scale | 4 | 0.8937 |
| Scale | 5 | 1.706 |
Separation and reliability
| Facet | SD of measures | RMSE | Separation | Reliability | Fixed χ² (all same) | df | p |
|---|---|---|---|---|---|---|---|
| Persons | 1.478 | 0.5525 | 2.481 | 0.8603 | 207.11 | 39 | < .001 |
| Raters | 0.3279 | 0.1636 | 1.737 | 0.7510 | 16.418 | 3 | < .001 |
| Items | 0.3473 | 0.1416 | 2.241 | 0.8339 | 17.984 | 2 | < .001 |
- Joint maximum likelihood (as in Facets): rater severities and item difficulties centered at 0, thresholds centered within each scale; local model SEs (1/√information). JML measures are slightly spread out when an element has few ratings.
The exact Python script · Python Python 3.13.5 · scipy 1.18.1 · pandas 3.1.0
# Many-facet Rasch model (rater severity)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method measurement.facets 1.0.0 · spec 5ce1e84cfc6bbf10
# Dataset: facets_sim (version 1)
# Runs on its own: outside the app, cs.publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
import numpy as np
import pandas as pd
import codesplash as cs
from codesplash.stats import facets as fc # many-facet Rasch, JML (twin of R's cs_facets_fit)
# %% Data
df = pd.read_parquet("tests/parity/fixtures/facets_sim.parquet", columns=["essay", "rater", "task", "score"])
n_input = len(df)
df["essay"] = pd.Categorical(df["essay"], categories=["e01", "e02", "e03", "e04", "e05", "e06", "e07", "e08", "e09", "e10", "e11", "e12", "e13", "e14", "e15", "e16", "e17", "e18", "e19", "e20", "e21", "e22", "e23", "e24", "e25", "e26", "e27", "e28", "e29", "e30", "e31", "e32", "e33", "e34", "e35", "e36", "e37", "e38", "e39", "e40", "e41"]) # stored level order
df["rater"] = pd.Categorical(df["rater"], categories=["r1", "r2", "r3", "r4"]) # stored level order
df["task"] = pd.Categorical(df["task"], categories=["argument", "evidence", "style"]) # stored level order
df = df.dropna(subset=["essay", "rater", "task", "score"]) # listwise deletion over the analysis columns
df["essay"] = df["essay"].cat.remove_unused_categories()
df["rater"] = df["rater"].cat.remove_unused_categories()
df["task"] = df["task"].cat.remove_unused_categories()
n_dropped = n_input - len(df)
warnings = []
if n_dropped:
warnings.append(cs.cs_warning("CS_W_ROWS_DROPPED", dropped=n_dropped, total=n_input))
if n_input and not len(df):
cs.cs_error("CS_E_NO_ROWS")
cs.check_finite_columns(df, ["essay", "rater", "task", "score"]) # infinite values stop the run (registry/errors.yaml)
# %% Facets and score categories
person_col, rater_col, score_col = "essay", "rater", "score"
item_col = "task"
persons = [str(x) for x in df[person_col].cat.categories]
raters = [str(x) for x in df[rater_col].cat.categories]
items = [str(x) for x in df[item_col].cat.categories] if item_col else ["All"]
note_gaps = ""
if isinstance(df[score_col].dtype, pd.CategoricalDtype):
cats = [str(x) for x in df[score_col].cat.categories]
x = df[score_col].cat.codes.to_numpy(dtype=np.int64)
else:
v = df[score_col].to_numpy(dtype=float)
bad = int(np.sum(v != np.round(v)))
if bad:
cs.cs_error("CS_E_INVALID_VALUES", column=score_col, requirement="whole numbers (ordered score categories)", count=bad)
vals = np.unique(v)
if len(vals) > 15:
cs.cs_error("CS_E_TOO_MANY_LEVELS", column=score_col, k=len(vals), max=15)
cats = [str(int(s)) for s in vals]
x = np.searchsorted(vals, v).astype(np.int64)
if len(vals) >= 2 and vals[-1] - vals[0] + 1 > len(vals):
note_gaps = f" Unused score values between {cats[0]} and {cats[-1]} were skipped: the categories are the {len(vals)} values used."
k = len(cats)
if k < 2:
cs.cs_error("CS_E_TOO_FEW_GROUPS", column=score_col, min=2, k=k)
if k > 15:
cs.cs_error("CS_E_TOO_MANY_LEVELS", column=score_col, k=k, max=15)
n_p, n_r, n_i = len(persons), len(raters), len(items)
if n_p < 2:
cs.cs_error("CS_E_TOO_FEW_GROUPS", column=person_col, min=2, k=n_p)
if n_r < 2:
cs.cs_error("CS_E_TOO_FEW_GROUPS", column=rater_col, min=2, k=n_r)
m = k - 1
person = df[person_col].cat.codes.to_numpy(dtype=np.int64)
rater = df[rater_col].cat.codes.to_numpy(dtype=np.int64)
item = df[item_col].cat.codes.to_numpy(dtype=np.int64) if item_col else np.zeros(len(df), dtype=np.int64)
thresholds = "shared"
if thresholds == "by_item" and not item_col:
thresholds = "shared"
groups, group_names = {"by_item": (item, items), "by_rater": (rater, raters)}.get(thresholds, (np.zeros(len(df), dtype=np.int64), ["Scale"]))
n_g = len(group_names)
# %% Extreme scores and linkage
active, flags = fc.extremes(person, rater, item, x, n_p, n_r, n_i, m)
if not active.any():
cs.cs_error("CS_E_UNDEFINED", what="Many-facet Rasch measures", reason="every person has the lowest or highest score in every rating")
subsets = fc.connected(person[active], rater[active], item[active], n_p, n_r, n_i)
if subsets > 1:
cs.cs_error("CS_E_UNDEFINED", what="Many-facet Rasch measures",
reason=f"the ratings split into {subsets} groups that share no raters, persons or items, so their measures can't be compared; link them with shared raters")
for g in np.unique(groups[active]):
used = np.unique(x[active & (groups == g)])
if len(used) < k:
miss = [cats[c] for c in range(k) if c not in used]
where = "" if thresholds == "shared" else f" for {group_names[g]}"
cs.cs_error("CS_E_UNDEFINED", what="The rating-scale thresholds",
reason=f"score {', '.join(miss)} is never given{where} once extreme scores are set aside; use shared thresholds or merge categories")
# %% Fit (joint maximum likelihood)
xa = x[active]
fit = fc.facets_fit(person[active], rater[active], item[active], xa, n_p, n_r, n_i, m, groups[active], n_g)
E, V = fit["expected"], fit["variance"]
z = (xa - E) / np.sqrt(V)
st_p = fc.element_stats(person[active], n_p, xa, E, V)
st_r = fc.element_stats(rater[active], n_r, xa, E, V)
st_i = fc.element_stats(item[active], n_i, xa, E, V)
sep_p = fc.separation(fit["theta"], st_p["se"])
sep_r = fc.separation(fit["alpha"], st_r["se"])
sep_i = fc.separation(fit["beta"], st_i["se"]) if item_col else None
nan = lambda v: None if v is None or not np.isfinite(v) else float(v) # noqa: E731
thr_label = {"shared": "one rating scale", "by_item": "a scale per item", "by_rater": "a scale per rater"}[thresholds]
misfit = [raters[j] for j in range(n_r) if np.isfinite(st_r["infit"][j]) and not (0.5 <= st_r["infit"][j] <= 1.5 and 0.5 <= st_r["outfit"][j] <= 1.5)]
values = {
"n_obs": float(len(x)), "n_used": float(active.sum()), "n_persons": float(n_p), "n_raters": float(n_r), "n_items": float(n_i if item_col else 0),
"n_extreme": float(np.sum(flags[0] != 0)), "categories": float(k), "loglik": float(fit["loglik"]), "iterations": float(fit["iterations"]),
"converged": 1.0 if fit["converged"] else 0.0,
"sep_person": nan(sep_p["separation"]), "rel_person": nan(sep_p["reliability"]),
"sep_rater": nan(sep_r["separation"]), "rel_rater": nan(sep_r["reliability"]),
"rater_chisq": nan(sep_r["chisq"]), "rater_df": nan(sep_r["df"]), "rater_p": nan(sep_r["p"]),
"severity_range": float(np.nanmax(fit["alpha"]) - np.nanmin(fit["alpha"])),
"share_z2": float(np.mean(np.abs(z) > 2)), "share_z3": float(np.mean(np.abs(z) > 3)),
"rater_misfit": float(len(misfit)), "thresholds_label": thr_label,
}
values.update({"sep_item": None, "rel_item": None, "item_chisq": None, "item_df": None, "item_p": None}) # no task facet: empty
if item_col:
values.update({"sep_item": nan(sep_i["separation"]), "rel_item": nan(sep_i["reliability"]), "item_chisq": nan(sep_i["chisq"]),
"item_df": nan(sep_i["df"]), "item_p": nan(sep_i["p"])})
for j, r in enumerate(raters):
values[f"severity[{r}]"] = nan(fit["alpha"][j])
values[f"se_severity[{r}]"] = nan(st_r["se"][j])
values[f"infit[{r}]"] = nan(st_r["infit"][j])
values[f"outfit[{r}]"] = nan(st_r["outfit"][j])
if item_col:
for i, it in enumerate(items):
values[f"difficulty[{it}]"] = nan(fit["beta"][i])
values[f"se_difficulty[{it}]"] = nan(st_i["se"][i])
tau = fit["tau"]
for g in range(n_g):
for h in range(m):
key = f"threshold[{cats[h + 1]}]" if thresholds == "shared" else f"threshold[{group_names[g]}|{cats[h + 1]}]"
values[key] = float(tau[g, h])
# %% Assumptions
counts = np.bincount(xa, minlength=k)
rare = [cats[c] for c in range(k) if counts[c] < 10]
assumptions = [
{"key": "rater_fit", "label": "Rater fit", "status": "warn" if misfit else "pass",
"detail": f"Infit or outfit outside 0.5–1.5: {', '.join(misfit)}." if misfit else "Every rater's infit and outfit mean squares are within 0.5–1.5."},
{"key": "residuals", "label": "Unexpected ratings", "status": "warn" if (values["share_z2"] > 0.05 or values["share_z3"] > 0.01) else "pass",
"detail": f"{values['share_z2']:.1%} of ratings have |z| > 2 and {values['share_z3']:.1%} have |z| > 3 (about 5% and 1% expected)."},
{"key": "category_use", "label": "Category use", "status": "warn" if rare else "pass",
"detail": f"Fewer than 10 ratings in: {', '.join(rare)}." if rare else "Every score category has at least 10 ratings."},
{"key": "extremes", "label": "Extreme scores", "status": "info",
"detail": f"{int(values['n_extreme'])} person(s) with the lowest or highest score in every rating were set aside (no finite estimate)." if values["n_extreme"] else "No person has an extreme score."},
{"key": "convergence", "label": "Convergence", "status": "pass" if fit["converged"] else "warn",
"detail": f"Newton–Raphson {'converged' if fit['converged'] else 'stopped before converging'} after {fit['iterations']} iterations."},
]
if not fit["converged"]:
warnings.append(cs.cs_warning("CS_W_NO_CONVERGENCE", what="Many-facet Rasch"))
# %% Tables
def facet_rows(names, meas, st, flg=None):
rows = []
for e, name in enumerate(names):
rows.append({"element": name, "measure": nan(meas[e]), "se": nan(st["se"][e]), "infit": nan(st["infit"][e]),
"outfit": nan(st["outfit"][e]), "count": int(st["count"][e]), "observed": nan(st["observed"][e]),
"status": ("lowest score" if flg is not None and flg[e] < 0 else "highest score" if flg is not None and flg[e] > 0 else "")})
return rows
fcols = lambda what: [ # noqa: E731
{"key": "element", "label": what, "type": "string"}, {"key": "measure", "label": "Measure (logits)", "type": "number"},
{"key": "se", "label": "SE", "type": "number"}, {"key": "infit", "label": "Infit MnSq", "type": "number"},
{"key": "outfit", "label": "Outfit MnSq", "type": "number"}, {"key": "count", "label": "Ratings", "type": "integer"},
{"key": "observed", "label": "Mean score (category)", "type": "number"}, {"key": "status", "label": "Extreme", "type": "string"}]
tables = [{"key": "raters", "title": "Raters (higher = more severe)", "columns": fcols("Rater"), "rows": facet_rows(raters, fit["alpha"], st_r, flags[1])}]
if item_col:
tables.append({"key": "items", "title": "Items (higher = harder)", "columns": fcols("Item"), "rows": facet_rows(items, fit["beta"], st_i, flags[2])})
tables.append({"key": "persons", "title": "Persons (higher = more able)", "columns": fcols("Person"), "rows": facet_rows(persons, fit["theta"], st_p, flags[0])})
thr_rows = [{"scale": group_names[g], "category": cats[h + 1], "threshold": float(tau[g, h])} for g in range(n_g) for h in range(m)]
tables.append({"key": "thresholds", "title": "Rasch–Andrich thresholds", "columns": [
{"key": "scale", "label": "Scale", "type": "string"}, {"key": "category", "label": "Step up to score", "type": "string"},
{"key": "threshold", "label": "Threshold (logits)", "type": "number"}], "rows": thr_rows})
sep_rows = [{"facet": "Persons", **{kk: nan(sep_p[kk]) for kk in ("sd", "rmse", "separation", "reliability", "chisq", "df", "p")}},
{"facet": "Raters", **{kk: nan(sep_r[kk]) for kk in ("sd", "rmse", "separation", "reliability", "chisq", "df", "p")}}]
if item_col:
sep_rows.append({"facet": "Items", **{kk: nan(sep_i[kk]) for kk in ("sd", "rmse", "separation", "reliability", "chisq", "df", "p")}})
tables.append({"key": "separation", "title": "Separation and reliability", "columns": [
{"key": "facet", "label": "Facet", "type": "string"}, {"key": "sd", "label": "SD of measures", "type": "number"},
{"key": "rmse", "label": "RMSE", "type": "number"}, {"key": "separation", "label": "Separation", "type": "number"},
{"key": "reliability", "label": "Reliability", "type": "number"}, {"key": "chisq", "label": "Fixed χ² (all same)", "type": "number"},
{"key": "df", "label": "df", "type": "integer"}, {"key": "p", "label": "p", "type": "pvalue"}], "rows": sep_rows})
# %% Charts
wm_f, wm_m, wm_l = [], [], []
facet_order = ["Persons", "Raters"] + (["Items"] if item_col else []) + ["Thresholds"]
for name, meas, labs in [("Persons", fit["theta"], persons), ("Raters", fit["alpha"], raters)] + ([("Items", fit["beta"], items)] if item_col else []):
for e, lab in enumerate(labs):
if np.isfinite(meas[e]):
wm_f.append(name)
wm_m.append(float(meas[e]))
wm_l.append(lab)
for g in range(n_g):
for h in range(m):
wm_f.append("Thresholds")
wm_m.append(float(tau[g, h]))
wm_l.append(cats[h + 1] if thresholds == "shared" else f"{group_names[g]} {cats[h + 1]}")
ra = np.isfinite(fit["alpha"])
charts = [
cs.chart("wright", "wright-map", "Wright map: persons, raters" + (", items" if item_col else "") + " and thresholds on one logit scale", {
"facet": cs.col("Facet", wm_f, "categorical", levels=facet_order),
"measure": cs.col("Measure (logits)", wm_m, "numeric"),
"label": cs.col("Element", wm_l, "categorical"),
}),
cs.chart("severity", "forest", "Rater severity (±1.96 SE)", {
"label": cs.col("Rater", [raters[j] for j in range(n_r) if ra[j]], "categorical", levels=[raters[j] for j in range(n_r) if ra[j]]),
"estimate": cs.col("Severity (logits)", [float(fit["alpha"][j]) for j in range(n_r) if ra[j]], "numeric"),
"low": cs.col("Low", [float(fit["alpha"][j] - 1.96 * st_r["se"][j]) for j in range(n_r) if ra[j]], "numeric"),
"high": cs.col("High", [float(fit["alpha"][j] + 1.96 * st_r["se"][j]) for j in range(n_r) if ra[j]], "numeric"),
}, controls={"reference": 0}),
]
grid = np.linspace(-6.0, 6.0, 121)
cur_t, cur_p, cur_s, cur_c = [], [], [], []
for g in range(n_g):
cum = np.concatenate([[0.0], np.cumsum(tau[g])])
s = grid[:, None] * np.arange(k)[None, :] - cum[None, :]
P = np.exp(s - s.max(axis=1, keepdims=True))
P /= P.sum(axis=1, keepdims=True)
for c in range(k):
cur_t += grid.tolist()
cur_p += P[:, c].tolist()
cur_s += [group_names[g]] * len(grid)
cur_c += [cats[c]] * len(grid)
charts.append(cs.chart("categories", "item-curves", "Category probability curves", {
"theta": cs.col("Measure relative to the rating (logits)", cur_t, "numeric"),
"probability": cs.col("Probability", cur_p, "numeric"),
"item": cs.col("Scale", cur_s, "categorical", levels=group_names),
"category": cs.col("Score", cur_c, "categorical", levels=cats),
}, controls={"kind": "icc"}))
# %% Result
cs.publish({
"method": "measurement.facets",
"methodVersion": "1.0.0",
"title": "Many-facet Rasch model",
"engine": cs.engine_info("numpy", "scipy", "codesplash"),
"n": int(active.sum()),
"summary": f"Many-facet Rasch model ({thr_label}) for {int(active.sum())} ratings by {n_r} raters: rater severities span {values['severity_range']:.2f} logits; rater separation reliability {values['rel_rater'] if values['rel_rater'] is not None else float('nan'):.2f}, person reliability {values['rel_person'] if values['rel_person'] is not None else float('nan'):.2f}.",
"apa": f"Many-facet Rasch model (JML): rater fixed χ²({int(sep_r['df'])}) = {cs.fmt_num(sep_r['chisq'], 2)}, {cs.fmt_p(sep_r['p'])}; rater separation reliability = {cs.fmt_num(sep_r['reliability'], 2, leading_zero=False)}",
"statistics": [{"key": "rater_chisq", "label": "Rater fixed χ²", "value": values["rater_chisq"]},
{"key": "rater_p", "label": "p", "value": values["rater_p"], "format": "p"},
{"key": "rel_rater", "label": "Rater separation reliability", "value": values["rel_rater"]}],
"tables": tables,
"assumptions": assumptions,
"warnings": warnings,
"notes": [f"Joint maximum likelihood (as in Facets): rater severities{' and item difficulties' if item_col else ''} centered at 0, thresholds centered within each scale; local model SEs (1/√information). JML measures are slightly spread out when an element has few ratings.{note_gaps}"],
"charts": charts,
"values": values,
})
Rater severities span 0.84 logits, and rater separation reliability is 0.75: raters are reliably different, which means a score depends on who rated it. Without the task facet, the two-facet fit's separation reliability for raters is 0.73. One severity per rater can't show a rater who is harsh only on one topic; look at rater-by-task residuals for that.
Where they stand in CodeSplash
Read| Entry | In CodeSplash |
|---|---|
| 2PL IRT (HME008) | Runs in CodeSplash: model 2PL in Item response theory (Rasch, 2PL, graded response), marginal maximum likelihood, with M2 fit and local-dependence (Q3) checks, Python ≡ R |
| Many-facet Rasch (HME009) | Runs in CodeSplash: Many-facet Rasch model (rater severity), one scale or a scale per rater or task, Python ≡ R |
Check your understanding
CheckpointCheck yourself
Two items have the same difficulty; item A has discrimination 2, item B 0.5. Which is more useful for telling apart respondents just above and just below that difficulty?
Show the answer
Answer: a
Information is : at the difficulty, A gives 16 times as much as B.
Check yourself
A 2PL item has discrimination 1. What is its item information for a respondent whose ability equals its difficulty?
Show the answer
Answer: 0.25
At , , so .
Check yourself
In an IRT analysis of AI benchmark results, unanswered items (timeouts) are coded as incorrect. What's the problem?
Show the answer
Answer: b
Treat not-reached and missing responses as their own states; decide deliberately how they enter the model.
Check yourself
In a many-facet Rasch model, what does a higher rater severity do to the expected score of an essay?
Show the answer
Answer: b
: severity subtracts on the logit scale, so the model credits essays scored by a harsh rater.
Check yourself
Rater separation reliability comes out high. Is that good news?
Show the answer
Answer: b
For persons, high separation is the goal. For raters, it signals the severity differences the model adjusts for, and a training need.
Recap
Recap- 2PL: ; information peaks at the difficulty.
- AIC and BIC can disagree; check absolute fit (M2) and local dependence too.
- Many-facet Rasch subtracts item difficulty, rater severity and thresholds on one logit scale.
- Raters must be linked by shared persons or tasks; high rater separation means unfair raw scores.
Concepts in this lesson