svgitem-curves
Item characteristic curves
How does the probability of each response change with the latent trait, item by item?
How to read it
- Read each curve as the probability of a correct response at each ability.
- Curves further right are harder items.
- Steeper curves separate people better.
- Callout 1: An easier item.
- Callout 2: A harder item.
- Callout 3: A steep curve: a discriminating item.
Watch out
- Item parameters assume the model fits: check item fit before you trust the curves.
Defaults
- Curves
- Characteristic (probability)
- Show one curve per item or one per response category.
- Also: Information
Pinned in the code
- Draws the run's numbers as given (computed by the Python/R engine); the chart computes nothing statistical.
- Without a category role every item is a curve in one panel; with one, each item is a panel and each category a curve (graded or partial-credit models).
# Item characteristic curves — Codesplash Chart Lab (recipe "item-curves")
# controls: kind=icc
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
try:
import codesplash as cs # optional: the app's chart theme
except ImportError:
cs = None
if cs:
cs.use_codesplash(dark=False)
PALETTE = cs.palette(dark=False)["categorical"] if cs else plt.rcParams["axes.prop_cycle"].by_key()["color"]
# non-colour encodings per series (same table as the app: series are never told apart by colour alone)
SERIES_DASHES = ["-", (0, (6, 3)), (0, (1.5, 2.5)), (0, (8, 3, 2, 3)), (0, (12, 4)), (0, (3, 3)), (0, (8, 2, 2, 2, 2, 2)), (0, (1.5, 5))]
df = pd.read_csv("item-curves-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["item"] = pd.Categorical(df["item"].astype("string"), categories=["Q1 (easy)", "Q2", "Q3", "Q4", "Q5 (hard)"])
def levels_of(s):
"""Declared level order (categoricals), else order of first appearance."""
if isinstance(s.dtype, pd.CategoricalDtype):
return [v for v in s.cat.categories if (s == v).any()]
return list(dict.fromkeys(s.dropna().astype(str)))
TH = "ability θ"
P = "P(correct)"
ITEM = "item"
CAT = None
items = levels_of(df[ITEM])
panels = items if CAT else [None]
fig, axes = plt.subplots(1, len(panels), figsize=(min(16, 3.4 * len(panels) + 1), 3.8), sharey=True, squeeze=False)
for ax, item in zip(axes[0], panels):
d = df if item is None else df[df[ITEM].astype(str) == str(item)]
key = CAT if CAT else ITEM
for i, lv in enumerate(levels_of(d[key])):
s = d[d[key].astype(str) == str(lv)].sort_values(TH)
ax.plot(s[TH], s[P], color=PALETTE[i % len(PALETTE)], linestyle=SERIES_DASHES[i % 8], linewidth=1.8, label=str(lv)) # dash per curve, as in the app
ax.set_title(str(item) if item is not None else "", fontsize=10, loc="left")
ax.set_xlabel(TH)
axes[0, 0].set_ylabel("P(response)")
axes[0, 0].legend(fontsize=8)
plt.show()Needs pandas, numpy, matplotlib · reads item-curves-demo.csv · app theme from the optional codesplash helper
# Item characteristic curves — Codesplash Chart Lab (recipe "item-curves")
# controls: kind=icc
import numpy as np
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
try:
import codesplash as cs # optional: the app's chart theme
except ImportError:
cs = None
if cs:
cs.use_codesplash(dark=False)
PALETTE = cs.palette(dark=False)["categorical"] if cs else px.colors.qualitative.Plotly
# non-colour encodings per series (same table as the app: series are never told apart by colour alone)
SERIES_DASHES = ["solid", "6px,3px", "1.5px,2.5px", "8px,3px,2px,3px", "12px,4px", "3px,3px", "8px,2px,2px,2px,2px,2px", "1.5px,5px"]
df = pd.read_csv("item-curves-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["item"] = pd.Categorical(df["item"].astype("string"), categories=["Q1 (easy)", "Q2", "Q3", "Q4", "Q5 (hard)"])
def levels_of(s):
"""Declared level order (categoricals), else order of first appearance."""
if isinstance(s.dtype, pd.CategoricalDtype):
return [v for v in s.cat.categories if (s == v).any()]
return list(dict.fromkeys(s.dropna().astype(str)))
TH = "ability θ"
P = "P(correct)"
ITEM = "item"
CAT = None
d = df.dropna(subset=[TH, P]).sort_values(TH)
fig = px.line(d, x=TH, y=P, color=CAT or ITEM, line_dash=CAT or ITEM, line_dash_sequence=SERIES_DASHES, facet_col=ITEM if CAT else None, color_discrete_sequence=PALETTE) # dash per curve, as in the app
fig.update_layout(yaxis_title="P(response)", legend_title=None)
fig.show()Needs pandas, numpy, plotly · reads item-curves-demo.csv · app theme from the optional codesplash helper
# Item characteristic curves — Codesplash Chart Lab (recipe "item-curves")
# controls: kind=icc
library(ggplot2)
has_cs <- isTRUE(requireNamespace("codesplashr", quietly = TRUE)) # optional: the app's chart theme
theme_cs <- if (has_cs) codesplashr::theme_codesplash(dark = FALSE) else theme_minimal()
cs_cat <- if (has_cs) codesplashr::cs_palette(dark = FALSE)$categorical else grDevices::palette.colors(8, "Okabe-Ito")
if (has_cs) update_geom_defaults("text", list(colour = codesplashr::cs_palette(dark = FALSE)$foreground))
# non-colour encodings per series (same table as the app: series are never told apart by colour alone)
cs_linetypes <- c("solid", "63", "23", "8323", "C4", "33", "822222", "25")
df <- read.csv("item-curves-demo.csv", check.names = FALSE, stringsAsFactors = FALSE, na.strings = "") # empty cells are missing; Chart Lab → Code → Download demo CSV
df[["item"]] <- factor(df[["item"]], levels = c("Q1 (easy)", "Q2", "Q3", "Q4", "Q5 (hard)"))
levels_of <- function(v) if (is.factor(v)) levels(droplevels(v)) else unique(as.character(v[!is.na(v)]))
th_col <- "ability θ"
p_col <- "P(correct)"
item_col <- "item"
cat_col <- NULL
d <- data.frame(th = df[[th_col]], p = df[[p_col]], item = factor(as.character(df[[item_col]]), levels = levels_of(df[[item_col]])))
d$curve <- if (is.null(cat_col)) d$item else factor(as.character(df[[cat_col]]), levels = levels_of(df[[cat_col]]))
p <- ggplot(d, aes(th, p, colour = curve, linetype = curve, group = interaction(item, curve))) + geom_line(linewidth = 0.9) + # dash per curve, as in the app
{ if (!is.null(cat_col)) facet_wrap(~item) } + scale_colour_manual(values = rep(cs_cat, 4)) + scale_linetype_manual(values = rep(cs_linetypes, 4)) +
labs(x = th_col, y = "P(response)", colour = NULL, linetype = NULL) + theme_cs
print(p)Needs ggplot2 · reads item-curves-demo.csv · app theme from the optional codesplashr helper