Rater severity with the many-facet Rasch model
When different raters score different people, raw averages mix ability with luck of the draw. Put persons, raters and tasks on one logit scale and read rater severity, fit and separation.
What runs in CodeSplash
- Many-facet Rasch model (rater severity) Verified in Python and R
You will be able to
- Explain how the many-facet Rasch model separates ability, rater severity and task difficulty
- Read a Wright map, rater severities and infit/outfit mean squares
- Interpret separation reliability for persons and for raters
Read first
Who scored you matters
In the appForty-one essays were each scored 1–5 by two of four raters on three tasks. Each essay got a different pair of raters. If one rater is harsh, every essay they scored looks worse than it is, and the raw averages can't tell you which.
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. explains each rating by three things on one logit scale: the essay's ability, minus the rater's severity, minus the task's difficulty. Rasch–Andrich thresholds turn that into the chance of each score. Because the raters overlap through shared essays, every rater's severity can be estimated against the same yardstick.
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,
})
Reading the Wright map
ReadThe Wright map puts everything on one vertical ruler. Essays are shown as a histogram, and raters and tasks as labeled points. Higher raters are harsher and higher tasks are harder. An essay level with a rater has even odds of scoring above rather than below the middle of the scale from that rater.
Here rater severities span 0.84 logits. r1 is the most lenient, at −0.54. r4 is the harshest, at 0.30. The fixed chi-square asks whether all four could really be equally severe: χ² = 16.4 on 3 df, p = p < .001. They differ.
Extreme scores
In the appOne essay got the top score from every rater on every task. Its measure would be infinite, so it's set aside and listed. 240 of 246 ratings are used.
Two reliabilities that mean opposite things
PredictPredict first
Person separation reliability is high, which is what you want. Rater separation reliability is also high, at 0.75. What does a high rater reliability mean?
Reveal
Bad news: the raters differ in severity. Separation reliability is how reliably a facet's elements are told apart. For persons, that's the point of the test. For raters, it means a person's score depends on who rated them. Person reliability here is 0.86.
Is each rater consistent?
ReadSeverity is about level. Fit is about consistency. The infit and outfit mean squares compare each rater's ratings with what the model expects:
- About : the rater varies as much as the model expects.
- Above : erratic. The rater gives surprising scores.
- Below : too predictable, often one category for everyone.
r4's infit is 1.27, inside the productive range of –, like every rater here. Across all ratings, 4.6% have standardized residuals beyond ±2, close to the 5% the model expects.
One scale, or a scale per rater?
ReadSome raters avoid the extreme categories; others use the whole scale. One scale per rater gives each rater their own thresholds, so you can see that, at the cost of needing every score used by every rater. With rater-specific scales, severities span 0.73 logits.
Many-facet Rasch model (JML): rater fixed χ²(3) = 12.91, p = .005; rater separation reliability = .68
- Rater fixed χ²
- 12.908
- p
- .005
- Rater separation reliability
- 0.6778
Assumptions
- Rater fit — Every rater's infit and outfit mean squares are within 0.5–1.5.
- Unexpected ratings — 3.8% 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.4957 | 0.1613 | 0.8285 | 0.8334 | 60 | 2.483 | |
| r2 | 0.1714 | 0.1776 | 1.151 | 1.124 | 60 | 1.783 | |
| r3 | 0.0934 | 0.1643 | 0.8129 | 0.8069 | 60 | 1.983 | |
| r4 | 0.2308 | 0.1550 | 1.193 | 1.220 | 60 | 1.850 |
Items (higher = harder)
| Item | Measure (logits) | SE | Infit MnSq | Outfit MnSq | Ratings | Mean score (category) | Extreme |
|---|---|---|---|---|---|---|---|
| argument | −0.4800 | 0.1423 | 1.267 | 1.225 | 80 | 2.325 | |
| evidence | 0.1394 | 0.1414 | 0.9512 | 0.9713 | 80 | 1.938 | |
| style | 0.3406 | 0.1423 | 0.7680 | 0.7920 | 80 | 1.813 |
Persons (higher = more able)
| Person | Measure (logits) | SE | Infit MnSq | Outfit MnSq | Ratings | Mean score (category) | Extreme |
|---|---|---|---|---|---|---|---|
| e01 | 2.408 | 0.6553 | 0.2920 | 0.3293 | 6 | 3.500 | |
| e02 | 0.5277 | 0.4794 | 0.3312 | 0.3344 | 6 | 2.167 | |
| e03 | 0.7351 | 0.4578 | 0.4190 | 0.4292 | 6 | 2.333 | |
| e04 | 1.330 | 0.4867 | 0.9352 | 0.8052 | 6 | 3 | |
| e05 | 0.0771 | 0.4629 | 0.2697 | 0.2757 | 6 | 2.167 | |
| e06 | −0.8914 | 0.5814 | 0.9098 | 0.8715 | 6 | 1.167 | |
| e07 | 0.7354 | 0.4781 | 0.7242 | 0.7061 | 6 | 2.667 | |
| e08 | −2.586 | 0.7404 | 0.7839 | 0.7943 | 6 | 0.5000 | |
| e09 | 0.8792 | 0.4659 | 0.3803 | 0.4105 | 6 | 2.667 | |
| e10 | −0.2387 | 0.4892 | 0.6531 | 0.6657 | 6 | 1.833 | |
| e11 | −4.034 | 1.093 | 0.9597 | 0.7817 | 6 | 0.1667 | |
| e12 | −0.9246 | 0.5223 | 0.8895 | 0.9183 | 6 | 1.167 | |
| e13 | −0.4842 | 0.5024 | 1.849 | 1.933 | 6 | 1.667 | |
| e14 | 0.5277 | 0.4794 | 1.183 | 1.179 | 6 | 2.167 | |
| e15 | −0.4035 | 0.4999 | 2.113 | 1.998 | 6 | 1.500 | |
| e16 | 0.0218 | 0.4671 | 0.4512 | 0.4376 | 6 | 2 | |
| e17 | 0.2922 | 0.4653 | 1.306 | 1.315 | 6 | 2.333 | |
| e18 | −0.2778 | 0.5277 | 1.363 | 1.362 | 6 | 1.500 | |
| e19 | −1.284 | 0.5100 | 0.9073 | 0.8481 | 6 | 1.167 | |
| e20 | −0.2778 | 0.5277 | 3.021 | 2.743 | 6 | 1.500 | |
| e21 | 1.100 | 0.4736 | 0.7372 | 0.7301 | 6 | 2.833 | |
| e22 | −3.572 | 0.8262 | 0.8767 | 0.9122 | 6 | 0.3333 | |
| e23 | 1.207 | 0.4782 | 1.009 | 1.015 | 6 | 2.667 | |
| e24 | −1.846 | 0.6007 | 0.6295 | 0.5835 | 6 | 0.6667 | |
| e25 | 0.6792 | 0.4797 | 1.910 | 2.005 | 6 | 2.500 | |
| e26 | 1.684 | 0.5031 | 0.6469 | 0.6616 | 6 | 3 | |
| e27 | 0.9431 | 0.4548 | 0.4037 | 0.3878 | 6 | 2.500 | |
| e28 | 1.100 | 0.4736 | 1.461 | 1.621 | 6 | 2.833 | |
| e29 | −2.205 | 0.6140 | 1.129 | 1.146 | 6 | 0.6667 | |
| e30 | 1.309 | 0.4577 | 0.9197 | 0.9175 | 6 | 2.667 | |
| e31 | 1.485 | 0.5308 | 0.7090 | 0.7688 | 6 | 3.167 | |
| e32 | −0.8914 | 0.5814 | 0.9574 | 0.9051 | 6 | 1.167 | |
| e33 | −0.4279 | 0.4832 | 1.739 | 1.845 | 6 | 1.667 | |
| e34 | 1.157 | 0.5008 | 0.8838 | 0.8915 | 6 | 2.833 | |
| e35 | −2.095 | 0.6502 | 2.024 | 2.000 | 6 | 0.6667 | |
| e36 | 1.812 | 0.4952 | 0.8333 | 0.8297 | 6 | 3.167 | |
| e37 | −0.2387 | 0.4892 | 1.441 | 1.327 | 6 | 1.833 | |
| e38 | 3.079 | 0.7515 | 0.8772 | 0.8866 | 6 | 3.667 | |
| e39 | 0.0775 | 0.4809 | 0.6933 | 0.6688 | 6 | 1.833 | |
| e40 | 1.576 | 0.5079 | 0.5477 | 0.6028 | 6 | 3.167 |
First 40 of 41 rows.
Rasch–Andrich thresholds
| Scale | Step up to score | Threshold (logits) |
|---|---|---|
| r1 | 2 | −2.208 |
| r1 | 3 | −0.1442 |
| r1 | 4 | 0.5278 |
| r1 | 5 | 1.825 |
| r2 | 2 | −2.963 |
| r2 | 3 | −0.0963 |
| r2 | 4 | 0.9112 |
| r2 | 5 | 2.148 |
| r3 | 2 | −1.746 |
| r3 | 3 | −0.8142 |
| r3 | 4 | 0.9746 |
| r3 | 5 | 1.586 |
| r4 | 2 | −2.125 |
| r4 | 3 | −0.3279 |
| r4 | 4 | 1.220 |
| r4 | 5 | 1.233 |
Separation and reliability
| Facet | SD of measures | RMSE | Separation | Reliability | Fixed χ² (all same) | df | p |
|---|---|---|---|---|---|---|---|
| Persons | 1.515 | 0.5569 | 2.531 | 0.8649 | 211.73 | 39 | < .001 |
| Raters | 0.2903 | 0.1648 | 1.450 | 0.6778 | 12.908 | 3 | .005 |
| Items | 0.3492 | 0.1420 | 2.247 | 0.8346 | 18.083 | 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 13b8d96213cf20a8
# 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 <- "by_rater"
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) = 12.91, p = .005; rater separation reliability = .68
- Rater fixed χ²
- 12.908
- p
- .005
- Rater separation reliability
- 0.6778
Assumptions
- Rater fit — Every rater's infit and outfit mean squares are within 0.5–1.5.
- Unexpected ratings — 3.8% 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.4957 | 0.1613 | 0.8285 | 0.8334 | 60 | 2.483 | |
| r2 | 0.1714 | 0.1776 | 1.151 | 1.124 | 60 | 1.783 | |
| r3 | 0.0934 | 0.1643 | 0.8129 | 0.8069 | 60 | 1.983 | |
| r4 | 0.2308 | 0.1550 | 1.193 | 1.220 | 60 | 1.850 |
Items (higher = harder)
| Item | Measure (logits) | SE | Infit MnSq | Outfit MnSq | Ratings | Mean score (category) | Extreme |
|---|---|---|---|---|---|---|---|
| argument | −0.4800 | 0.1423 | 1.267 | 1.225 | 80 | 2.325 | |
| evidence | 0.1394 | 0.1414 | 0.9512 | 0.9713 | 80 | 1.938 | |
| style | 0.3406 | 0.1423 | 0.7680 | 0.7920 | 80 | 1.813 |
Persons (higher = more able)
| Person | Measure (logits) | SE | Infit MnSq | Outfit MnSq | Ratings | Mean score (category) | Extreme |
|---|---|---|---|---|---|---|---|
| e01 | 2.408 | 0.6553 | 0.2920 | 0.3293 | 6 | 3.500 | |
| e02 | 0.5277 | 0.4794 | 0.3312 | 0.3344 | 6 | 2.167 | |
| e03 | 0.7351 | 0.4578 | 0.4190 | 0.4292 | 6 | 2.333 | |
| e04 | 1.330 | 0.4867 | 0.9352 | 0.8052 | 6 | 3 | |
| e05 | 0.0771 | 0.4629 | 0.2697 | 0.2757 | 6 | 2.167 | |
| e06 | −0.8914 | 0.5814 | 0.9098 | 0.8715 | 6 | 1.167 | |
| e07 | 0.7354 | 0.4781 | 0.7242 | 0.7061 | 6 | 2.667 | |
| e08 | −2.586 | 0.7404 | 0.7839 | 0.7943 | 6 | 0.5000 | |
| e09 | 0.8792 | 0.4659 | 0.3803 | 0.4105 | 6 | 2.667 | |
| e10 | −0.2387 | 0.4892 | 0.6531 | 0.6657 | 6 | 1.833 | |
| e11 | −4.034 | 1.093 | 0.9597 | 0.7817 | 6 | 0.1667 | |
| e12 | −0.9246 | 0.5223 | 0.8895 | 0.9183 | 6 | 1.167 | |
| e13 | −0.4842 | 0.5024 | 1.849 | 1.933 | 6 | 1.667 | |
| e14 | 0.5277 | 0.4794 | 1.183 | 1.179 | 6 | 2.167 | |
| e15 | −0.4035 | 0.4999 | 2.113 | 1.998 | 6 | 1.500 | |
| e16 | 0.0218 | 0.4671 | 0.4512 | 0.4376 | 6 | 2 | |
| e17 | 0.2922 | 0.4653 | 1.306 | 1.315 | 6 | 2.333 | |
| e18 | −0.2778 | 0.5277 | 1.363 | 1.362 | 6 | 1.500 | |
| e19 | −1.284 | 0.5100 | 0.9073 | 0.8481 | 6 | 1.167 | |
| e20 | −0.2778 | 0.5277 | 3.021 | 2.743 | 6 | 1.500 | |
| e21 | 1.100 | 0.4736 | 0.7372 | 0.7301 | 6 | 2.833 | |
| e22 | −3.572 | 0.8262 | 0.8767 | 0.9122 | 6 | 0.3333 | |
| e23 | 1.207 | 0.4782 | 1.009 | 1.015 | 6 | 2.667 | |
| e24 | −1.846 | 0.6007 | 0.6295 | 0.5835 | 6 | 0.6667 | |
| e25 | 0.6792 | 0.4797 | 1.910 | 2.005 | 6 | 2.500 | |
| e26 | 1.684 | 0.5031 | 0.6469 | 0.6616 | 6 | 3 | |
| e27 | 0.9431 | 0.4548 | 0.4037 | 0.3878 | 6 | 2.500 | |
| e28 | 1.100 | 0.4736 | 1.461 | 1.621 | 6 | 2.833 | |
| e29 | −2.205 | 0.6140 | 1.129 | 1.146 | 6 | 0.6667 | |
| e30 | 1.309 | 0.4577 | 0.9197 | 0.9175 | 6 | 2.667 | |
| e31 | 1.485 | 0.5308 | 0.7090 | 0.7688 | 6 | 3.167 | |
| e32 | −0.8914 | 0.5814 | 0.9574 | 0.9051 | 6 | 1.167 | |
| e33 | −0.4279 | 0.4832 | 1.739 | 1.845 | 6 | 1.667 | |
| e34 | 1.157 | 0.5008 | 0.8838 | 0.8915 | 6 | 2.833 | |
| e35 | −2.095 | 0.6502 | 2.024 | 2.000 | 6 | 0.6667 | |
| e36 | 1.812 | 0.4952 | 0.8333 | 0.8297 | 6 | 3.167 | |
| e37 | −0.2387 | 0.4892 | 1.441 | 1.327 | 6 | 1.833 | |
| e38 | 3.079 | 0.7515 | 0.8772 | 0.8866 | 6 | 3.667 | |
| e39 | 0.0775 | 0.4809 | 0.6933 | 0.6688 | 6 | 1.833 | |
| e40 | 1.576 | 0.5079 | 0.5477 | 0.6028 | 6 | 3.167 |
First 40 of 41 rows.
Rasch–Andrich thresholds
| Scale | Step up to score | Threshold (logits) |
|---|---|---|
| r1 | 2 | −2.208 |
| r1 | 3 | −0.1442 |
| r1 | 4 | 0.5278 |
| r1 | 5 | 1.825 |
| r2 | 2 | −2.963 |
| r2 | 3 | −0.0963 |
| r2 | 4 | 0.9112 |
| r2 | 5 | 2.148 |
| r3 | 2 | −1.746 |
| r3 | 3 | −0.8142 |
| r3 | 4 | 0.9746 |
| r3 | 5 | 1.586 |
| r4 | 2 | −2.125 |
| r4 | 3 | −0.3279 |
| r4 | 4 | 1.220 |
| r4 | 5 | 1.233 |
Separation and reliability
| Facet | SD of measures | RMSE | Separation | Reliability | Fixed χ² (all same) | df | p |
|---|---|---|---|---|---|---|---|
| Persons | 1.515 | 0.5569 | 2.531 | 0.8649 | 211.73 | 39 | < .001 |
| Raters | 0.2903 | 0.1648 | 1.450 | 0.6778 | 12.908 | 3 | .005 |
| Items | 0.3492 | 0.1420 | 2.247 | 0.8346 | 18.083 | 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 13b8d96213cf20a8
# 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 = "by_rater"
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,
})
Shortened for the Academy: 3 chart(s) dropped to stay under 100 KB; 3 chart(s) dropped to stay under 100 KB.
If every rating is of the same thing, leave the task role empty. The model then has two facets, persons and raters.
Many-facet Rasch model (JML): rater fixed χ²(3) = 15.10, p = .002; rater separation reliability = .73
- Rater fixed χ²
- 15.103
- p
- .002
- Rater separation reliability
- 0.7292
Plots
View data
| Facet | Element | Measure (logits) |
|---|---|---|
| Persons | e01 | 2.074 |
| Persons | e02 | 0.4780 |
| Persons | e03 | 0.7107 |
| Persons | e04 | 1.276 |
| Persons | e05 | 0.1252 |
| Persons | e06 | −0.7728 |
| Persons | e07 | 0.7155 |
| Persons | e08 | −2.179 |
| Persons | e09 | 0.8450 |
| Persons | e10 | −0.2065 |
| Persons | e11 | −3.657 |
| Persons | e12 | −0.8589 |
| Persons | e13 | −0.4264 |
| Persons | e14 | 0.4780 |
| Persons | e15 | −0.3402 |
| Persons | e16 | 0.0393 |
| Persons | e17 | 0.3219 |
| Persons | e18 | −0.2541 |
| Persons | e19 | −1.255 |
| Persons | e20 | −0.2541 |
| Persons | e21 | 1.054 |
| Persons | e22 | −3.140 |
| Persons | e23 | 1.059 |
| Persons | e24 | −1.841 |
| Persons | e25 | 0.6031 |
| Persons | e26 | 1.473 |
| Persons | e27 | 0.9035 |
| Persons | e28 | 1.054 |
| Persons | e29 | −2.239 |
| Persons | e30 | 1.181 |
| Persons | e31 | 1.374 |
| Persons | e32 | −0.7728 |
| Persons | e33 | −0.3916 |
| Persons | e34 | 1.012 |
| Persons | e35 | −1.878 |
| Persons | e36 | 1.747 |
| Persons | e37 | −0.2065 |
| Persons | e38 | 2.727 |
| Persons | e39 | 0.1099 |
| Persons | e40 | 1.518 |
| Raters | r1 | −0.5006 |
| Raters | r2 | 0.1971 |
| Raters | r3 | 0.0290 |
| Raters | r4 | 0.2745 |
| Thresholds | 2 | −2.091 |
| Thresholds | 3 | −0.2854 |
| Thresholds | 4 | 0.8399 |
| Thresholds | 5 | 1.537 |
View data
| Severity (logits) | High | Rater | Low |
|---|---|---|---|
| −0.5006 | −0.1961 | r1 | −0.8050 |
| 0.1971 | 0.5157 | r2 | −0.1216 |
| 0.0290 | 0.3389 | r3 | −0.2809 |
| 0.2745 | 0.5745 | r4 | −0.0255 |
View data
| Score | Scale | Probability | Measure relative to the rating (logits) |
|---|---|---|---|
| 1 | Scale | 0.9803 | −6 |
| 1 | Scale | 0.9782 | −5.900 |
| 1 | Scale | 0.9760 | −5.800 |
| 1 | Scale | 0.9735 | −5.700 |
| 1 | Scale | 0.9708 | −5.600 |
| 1 | Scale | 0.9678 | −5.500 |
| 1 | Scale | 0.9645 | −5.400 |
| 1 | Scale | 0.9609 | −5.300 |
| 1 | Scale | 0.9569 | −5.200 |
| 1 | Scale | 0.9526 | −5.100 |
| 1 | Scale | 0.9478 | −5 |
| 1 | Scale | 0.9426 | −4.900 |
| 1 | Scale | 0.9369 | −4.800 |
| 1 | Scale | 0.9306 | −4.700 |
| 1 | Scale | 0.9238 | −4.600 |
| 1 | Scale | 0.9164 | −4.500 |
| 1 | Scale | 0.9082 | −4.400 |
| 1 | Scale | 0.8994 | −4.300 |
| 1 | Scale | 0.8898 | −4.200 |
| 1 | Scale | 0.8794 | −4.100 |
| 1 | Scale | 0.8681 | −4 |
| 1 | Scale | 0.8559 | −3.900 |
| 1 | Scale | 0.8428 | −3.800 |
| 1 | Scale | 0.8286 | −3.700 |
| 1 | Scale | 0.8134 | −3.600 |
| 1 | Scale | 0.7972 | −3.500 |
| 1 | Scale | 0.7798 | −3.400 |
| 1 | Scale | 0.7613 | −3.300 |
| 1 | Scale | 0.7417 | −3.200 |
| 1 | Scale | 0.7210 | −3.100 |
| 1 | Scale | 0.6991 | −3 |
| 1 | Scale | 0.6762 | −2.900 |
| 1 | Scale | 0.6522 | −2.800 |
| 1 | Scale | 0.6273 | −2.700 |
| 1 | Scale | 0.6014 | −2.600 |
| 1 | Scale | 0.5748 | −2.500 |
| 1 | Scale | 0.5474 | −2.400 |
| 1 | Scale | 0.5195 | −2.300 |
| 1 | Scale | 0.4912 | −2.200 |
| 1 | Scale | 0.4626 | −2.100 |
| 1 | Scale | 0.4338 | −2 |
| 1 | Scale | 0.4052 | −1.900 |
| 1 | Scale | 0.3767 | −1.800 |
| 1 | Scale | 0.3487 | −1.700 |
| 1 | Scale | 0.3212 | −1.600 |
| 1 | Scale | 0.2944 | −1.500 |
| 1 | Scale | 0.2684 | −1.400 |
| 1 | Scale | 0.2435 | −1.300 |
| 1 | Scale | 0.2197 | −1.200 |
| 1 | Scale | 0.1971 | −1.100 |
| 1 | Scale | 0.1759 | −1 |
| 1 | Scale | 0.1559 | −0.9000 |
| 1 | Scale | 0.1374 | −0.8000 |
| 1 | Scale | 0.1204 | −0.7000 |
| 1 | Scale | 0.1047 | −0.6000 |
| 1 | Scale | 0.0905 | −0.5000 |
| 1 | Scale | 0.0777 | −0.4000 |
| 1 | Scale | 0.0662 | −0.3000 |
| 1 | Scale | 0.0560 | −0.2000 |
| 1 | Scale | 0.0470 | −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 — 2.5% of ratings have |z| > 2 and 0.8% 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.5006 | 0.1553 | 0.7991 | 0.8052 | 60 | 2.483 | |
| r2 | 0.1971 | 0.1626 | 1.004 | 1.005 | 60 | 1.783 | |
| r3 | 0.0290 | 0.1581 | 0.8604 | 0.8381 | 60 | 1.983 | |
| r4 | 0.2745 | 0.1530 | 1.326 | 1.332 | 60 | 1.850 |
Persons (higher = more able)
| Person | Measure (logits) | SE | Infit MnSq | Outfit MnSq | Ratings | Mean score (category) | Extreme |
|---|---|---|---|---|---|---|---|
| e01 | 2.074 | 0.6089 | 0.2649 | 0.2853 | 6 | 3.500 | |
| e02 | 0.4780 | 0.4427 | 0.5333 | 0.5362 | 6 | 2.167 | |
| e03 | 0.7107 | 0.4394 | 0.5747 | 0.5719 | 6 | 2.333 | |
| e04 | 1.276 | 0.4798 | 1.231 | 1.112 | 6 | 3 | |
| e05 | 0.1252 | 0.4454 | 0.3143 | 0.3190 | 6 | 2.167 | |
| e06 | −0.7728 | 0.5301 | 0.7841 | 0.7887 | 6 | 1.167 | |
| e07 | 0.7155 | 0.4478 | 0.7715 | 0.7613 | 6 | 2.667 | |
| e08 | −2.179 | 0.6838 | 0.6891 | 0.6893 | 6 | 0.5000 | |
| e09 | 0.8450 | 0.4529 | 0.6918 | 0.6766 | 6 | 2.667 | |
| e10 | −0.2065 | 0.4629 | 0.8199 | 0.8498 | 6 | 1.833 | |
| e11 | −3.657 | 1.059 | 0.9628 | 1.017 | 6 | 0.1667 | |
| e12 | −0.8589 | 0.5301 | 0.9278 | 0.9291 | 6 | 1.167 | |
| e13 | −0.4264 | 0.4753 | 1.747 | 1.807 | 6 | 1.667 | |
| e14 | 0.4780 | 0.4427 | 1.317 | 1.312 | 6 | 2.167 | |
| e15 | −0.3402 | 0.4900 | 2.414 | 2.452 | 6 | 1.500 | |
| e16 | 0.0393 | 0.4546 | 0.5375 | 0.5101 | 6 | 2 | |
| e17 | 0.3219 | 0.4423 | 1.283 | 1.284 | 6 | 2.333 | |
| e18 | −0.2541 | 0.4899 | 0.8539 | 0.8595 | 6 | 1.500 | |
| e19 | −1.255 | 0.5302 | 1.312 | 1.213 | 6 | 1.167 | |
| e20 | −0.2541 | 0.4899 | 2.696 | 2.691 | 6 | 1.500 | |
| e21 | 1.054 | 0.4631 | 0.9262 | 0.9055 | 6 | 2.833 | |
| e22 | −3.140 | 0.7980 | 0.8805 | 0.9229 | 6 | 0.3333 | |
| e23 | 1.059 | 0.4437 | 0.9439 | 0.9405 | 6 | 2.667 | |
| e24 | −1.841 | 0.6242 | 0.6078 | 0.5967 | 6 | 0.6667 | |
| e25 | 0.6031 | 0.4459 | 1.081 | 1.065 | 6 | 2.500 | |
| e26 | 1.473 | 0.4704 | 0.8905 | 0.8915 | 6 | 3 | |
| e27 | 0.9035 | 0.4396 | 0.2619 | 0.2620 | 6 | 2.500 | |
| e28 | 1.054 | 0.4631 | 1.456 | 1.410 | 6 | 2.833 | |
| e29 | −2.239 | 0.6258 | 1.159 | 1.116 | 6 | 0.6667 | |
| e30 | 1.181 | 0.4434 | 1.443 | 1.440 | 6 | 2.667 | |
| e31 | 1.374 | 0.5007 | 0.4913 | 0.5013 | 6 | 3.167 | |
| e32 | −0.7728 | 0.5301 | 0.8099 | 0.8189 | 6 | 1.167 | |
| e33 | −0.3916 | 0.4757 | 2.223 | 2.442 | 6 | 1.667 | |
| e34 | 1.012 | 0.4613 | 0.7717 | 0.8228 | 6 | 2.833 | |
| e35 | −1.878 | 0.6240 | 1.245 | 1.229 | 6 | 0.6667 | |
| e36 | 1.747 | 0.4972 | 1.164 | 1.180 | 6 | 3.167 | |
| e37 | −0.2065 | 0.4629 | 0.7807 | 0.7501 | 6 | 1.833 | |
| e38 | 2.727 | 0.7230 | 0.6992 | 0.7030 | 6 | 3.667 | |
| e39 | 0.1099 | 0.4605 | 0.4899 | 0.4903 | 6 | 1.833 | |
| e40 | 1.518 | 0.5056 | 0.6938 | 0.6510 | 6 | 3.167 |
First 40 of 41 rows.
Rasch–Andrich thresholds
| Scale | Step up to score | Threshold (logits) |
|---|---|---|
| Scale | 2 | −2.091 |
| Scale | 3 | −0.2854 |
| Scale | 4 | 0.8399 |
| Scale | 5 | 1.537 |
Separation and reliability
| Facet | SD of measures | RMSE | Separation | Reliability | Fixed χ² (all same) | df | p |
|---|---|---|---|---|---|---|---|
| Persons | 1.378 | 0.5350 | 2.374 | 0.8493 | 188.72 | 39 | < .001 |
| Raters | 0.3023 | 0.1573 | 1.641 | 0.7292 | 15.103 | 3 | .002 |
- Joint maximum likelihood (as in Facets): rater severities 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 dc9ce76f558ce4b6
# 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", "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 <- df[stats::complete.cases(df[c("essay", "rater", "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", "score")) # infinite values stop the run (registry/errors.yaml)
# %% Facets and score categories
person_col <- "essay"
rater_col <- "rater"
score_col <- "score"
item_col <- NULL
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) = 15.10, p = .002; rater separation reliability = .73
- Rater fixed χ²
- 15.103
- p
- .002
- Rater separation reliability
- 0.7292
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 — 2.5% of ratings have |z| > 2 and 0.8% 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.5006 | 0.1553 | 0.7991 | 0.8052 | 60 | 2.483 | |
| r2 | 0.1971 | 0.1626 | 1.004 | 1.005 | 60 | 1.783 | |
| r3 | 0.0290 | 0.1581 | 0.8604 | 0.8381 | 60 | 1.983 | |
| r4 | 0.2745 | 0.1530 | 1.326 | 1.332 | 60 | 1.850 |
Persons (higher = more able)
| Person | Measure (logits) | SE | Infit MnSq | Outfit MnSq | Ratings | Mean score (category) | Extreme |
|---|---|---|---|---|---|---|---|
| e01 | 2.074 | 0.6089 | 0.2649 | 0.2853 | 6 | 3.500 | |
| e02 | 0.4780 | 0.4427 | 0.5333 | 0.5362 | 6 | 2.167 | |
| e03 | 0.7107 | 0.4394 | 0.5747 | 0.5719 | 6 | 2.333 | |
| e04 | 1.276 | 0.4798 | 1.231 | 1.112 | 6 | 3 | |
| e05 | 0.1252 | 0.4454 | 0.3143 | 0.3190 | 6 | 2.167 | |
| e06 | −0.7728 | 0.5301 | 0.7841 | 0.7887 | 6 | 1.167 | |
| e07 | 0.7155 | 0.4478 | 0.7715 | 0.7613 | 6 | 2.667 | |
| e08 | −2.179 | 0.6838 | 0.6891 | 0.6893 | 6 | 0.5000 | |
| e09 | 0.8450 | 0.4529 | 0.6918 | 0.6766 | 6 | 2.667 | |
| e10 | −0.2065 | 0.4629 | 0.8199 | 0.8498 | 6 | 1.833 | |
| e11 | −3.657 | 1.059 | 0.9628 | 1.017 | 6 | 0.1667 | |
| e12 | −0.8589 | 0.5301 | 0.9278 | 0.9291 | 6 | 1.167 | |
| e13 | −0.4264 | 0.4753 | 1.747 | 1.807 | 6 | 1.667 | |
| e14 | 0.4780 | 0.4427 | 1.317 | 1.312 | 6 | 2.167 | |
| e15 | −0.3402 | 0.4900 | 2.414 | 2.452 | 6 | 1.500 | |
| e16 | 0.0393 | 0.4546 | 0.5375 | 0.5101 | 6 | 2 | |
| e17 | 0.3219 | 0.4423 | 1.283 | 1.284 | 6 | 2.333 | |
| e18 | −0.2541 | 0.4899 | 0.8539 | 0.8595 | 6 | 1.500 | |
| e19 | −1.255 | 0.5302 | 1.312 | 1.213 | 6 | 1.167 | |
| e20 | −0.2541 | 0.4899 | 2.696 | 2.691 | 6 | 1.500 | |
| e21 | 1.054 | 0.4631 | 0.9262 | 0.9055 | 6 | 2.833 | |
| e22 | −3.140 | 0.7980 | 0.8805 | 0.9229 | 6 | 0.3333 | |
| e23 | 1.059 | 0.4437 | 0.9439 | 0.9405 | 6 | 2.667 | |
| e24 | −1.841 | 0.6242 | 0.6078 | 0.5967 | 6 | 0.6667 | |
| e25 | 0.6031 | 0.4459 | 1.081 | 1.065 | 6 | 2.500 | |
| e26 | 1.473 | 0.4704 | 0.8905 | 0.8915 | 6 | 3 | |
| e27 | 0.9035 | 0.4396 | 0.2619 | 0.2620 | 6 | 2.500 | |
| e28 | 1.054 | 0.4631 | 1.456 | 1.410 | 6 | 2.833 | |
| e29 | −2.239 | 0.6258 | 1.159 | 1.116 | 6 | 0.6667 | |
| e30 | 1.181 | 0.4434 | 1.443 | 1.440 | 6 | 2.667 | |
| e31 | 1.374 | 0.5007 | 0.4913 | 0.5013 | 6 | 3.167 | |
| e32 | −0.7728 | 0.5301 | 0.8099 | 0.8189 | 6 | 1.167 | |
| e33 | −0.3916 | 0.4757 | 2.223 | 2.442 | 6 | 1.667 | |
| e34 | 1.012 | 0.4613 | 0.7717 | 0.8228 | 6 | 2.833 | |
| e35 | −1.878 | 0.6240 | 1.245 | 1.229 | 6 | 0.6667 | |
| e36 | 1.747 | 0.4972 | 1.164 | 1.180 | 6 | 3.167 | |
| e37 | −0.2065 | 0.4629 | 0.7807 | 0.7501 | 6 | 1.833 | |
| e38 | 2.727 | 0.7230 | 0.6992 | 0.7030 | 6 | 3.667 | |
| e39 | 0.1099 | 0.4605 | 0.4899 | 0.4903 | 6 | 1.833 | |
| e40 | 1.518 | 0.5056 | 0.6938 | 0.6510 | 6 | 3.167 |
First 40 of 41 rows.
Rasch–Andrich thresholds
| Scale | Step up to score | Threshold (logits) |
|---|---|---|
| Scale | 2 | −2.091 |
| Scale | 3 | −0.2854 |
| Scale | 4 | 0.8399 |
| Scale | 5 | 1.537 |
Separation and reliability
| Facet | SD of measures | RMSE | Separation | Reliability | Fixed χ² (all same) | df | p |
|---|---|---|---|---|---|---|---|
| Persons | 1.378 | 0.5350 | 2.374 | 0.8493 | 188.72 | 39 | < .001 |
| Raters | 0.3023 | 0.1573 | 1.641 | 0.7292 | 15.103 | 3 | .002 |
- Joint maximum likelihood (as in Facets): rater severities 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 dc9ce76f558ce4b6
# 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", "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 = df.dropna(subset=["essay", "rater", "score"]) # listwise deletion over the analysis columns
df["essay"] = df["essay"].cat.remove_unused_categories()
df["rater"] = df["rater"].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", "score"]) # infinite values stop the run (registry/errors.yaml)
# %% Facets and score categories
person_col, rater_col, score_col = "essay", "rater", "score"
item_col = None
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,
})
Check your understanding
CheckpointCheck yourself
Essay A, scored by a harsh rater, averages 3.0. Essay B, scored by a lenient rater, averages 3.5. What can the many-facet Rasch model add?
Show the answer
Answer: b
Raw averages mix ability with rater severity. The model estimates severity from all the shared ratings and puts both essays on the same scale.
Check yourself
A rater's infit mean square is 0.3, and they gave almost everyone a 3. What's the concern?
Show the answer
Answer: b
Mean squares far below 1 mean less variation than the model expects, typically central tendency. Above 1.5 would mean erratic ratings.
Check yourself
Two teams of raters scored two separate groups of students, with no student scored by both teams. What happens?
Show the answer
Answer: b
Severities and abilities are only identified relative to each other through shared ratings. CodeSplash stops with a message when the design splits into unlinked groups.
Recap
Recap- The many-facet Rasch model puts persons, raters and tasks on one logit scale.
- Rater severity is level, and infit/outfit is consistency; keep mean squares within 0.5–1.5.
- High person reliability is good. High rater reliability means the raters really differ.
- Raters must be linked through shared persons for their severities to be comparable.
Concepts in this lesson