Product Research Pricing About Careers Blog Private beta Talk to us Get the private beta →
Research Skill measurement · 18 April 2023 · 22 min read

An item bank for code comprehension: calibration, adaptive testing and fairness checks with item response theory

Before we can say anything about what AI assistance does to an engineer’s understanding, we need an instrument that measures understanding on a scale, not a percent-correct score that changes meaning with every question set. This is the measurement plan, tested end to end on simulated engineers before a single real one sits it.

ReportAWL-2023-01
Versionv1.1
AreaSkill measurement

Updated 30 May 2023 · v1.1 re-runs the DIF analysis with items re-drawn per replicate, which removed a non-monotone artefact in v1.0

Item characteristic curves of a 120-item bank, a few picked out in amber Cover generated from this paper’s simulation
Abstract

We specify and test, entirely in simulation, a 120-item code-comprehension bank scored with a two-parameter logistic (2PL) item response model. Items are calibrated by marginal maximum likelihood (Bock-Aitkin EM) from a planned-missing design in which each engineer sees one of eight overlapping 30-item booklets. With 1,200 calibration respondents (about 300 responses per item), discrimination and difficulty are recovered with root-mean-square errors of 0.22 and 0.19; halving the sample to 600 raises them to 0.29 and 0.25. Scoring engineers by expected a posteriori (EAP) ability rather than percent correct makes scores from different booklets more comparable (alternate-form correlation 0.87 against 0.83). A computerised adaptive test stopping at a posterior standard deviation of 0.30 needs a mean of 22.9 items to match the accuracy of the best fixed 30-item form, and is more accurate in the tails (RMSE 0.41 against 0.50 for |θ| > 1.5). Without exposure control, 16 items are shown to more than half of all test-takers; randomesque selection from the top 15 cuts the most-exposed item from 100% to 73% for two extra items. Mantel-Haenszel screening detects a 0.8-logit language-background bias in 79% of affected items at 2,400 respondents and 28% at 600, with a false-positive rate near 3%.

22.9mean items for an adaptive test to match a 30-item fixed form
0.19RMSE of item difficulty with 1,200 calibration respondents
28% vs 79%power to detect a large language-background bias at 600 against 2,400 respondents

Every claim AI Work Lab wants to make eventually depends on one measurement: whether an engineer understands a piece of code. The obvious instrument, a quiz scored as percent correct, has a defect that becomes fatal in a longitudinal study. Its scale is defined by the questions. Change the questions, as you must when you test the same person every month, and a score of 70% no longer means what it meant last time.

Item response theory fixes this by modelling each question separately and putting people and questions on one scale. The cost is a calibration step, and a calibration sample we do not yet have. So we did the work in the order a careful lab should: specify the model, the design, the scoring, the adaptive algorithm and the fairness checks, then run the whole pipeline on simulated engineers whose true ability is known, and only then write questions for real ones. This report is that rehearsal. It contains no data from people.

What this paper is

A simulation study of a measurement design. Every number below comes from engineers and items generated by the scripts listed under Artefacts. Item parameters were drawn to resemble published programming-assessment banks; they are not estimates from any real test.

The model

Each item j is a short task about a real diff: predict the output, find the line that fails under a given input, say what changes if a condition is flipped. A response is right or wrong. The 2PL model gives the probability that an engineer with ability θ answers correctly as

P(Xij = 1 | θi) = 1 / (1 + exp[ −aj(θi − bj) ])(1)

where bj is the item’s difficulty, the ability at which the chance of success is one half, and aj its discrimination, how sharply it separates engineers just below that point from those just above. The information an item provides about θ, and so how much it reduces uncertainty, is

Ij(θ) = aj2 Pj(θ) [1 − Pj(θ)](2)

which peaks at θ = bj and scales with the square of discrimination. Test information is the sum over the items administered, and the standard error of an ability estimate is roughly its inverse square root. Everything that follows, from booklet design to adaptive testing, is an exercise in putting information where it is needed.

We chose the 2PL over the three-parameter model because our items are open-response, so guessing is negligible, and over the Rasch model because items about real code will differ in how cleanly they separate engineers. A multidimensional model with one dimension per concept domain is the natural extension once there is enough data to support it.

Calibration from a planned-missing design

No engineer will answer 120 questions. Instead the bank is split into 16 blocks of seven or eight items, and each of eight booklets combines four blocks, so that every block appears in two booklets and every pair of booklets is linked through shared blocks. Each engineer answers one booklet of about 30 items. Responses to unseen items are missing by design, which is ignorable for likelihood-based estimation.

Item parameters are estimated by marginal maximum likelihood, integrating ability out against a standard normal prior with the EM algorithm of Bock and Aitkin. On a 41-point quadrature grid q1, ..., q41 with weights wk, the E-step computes each engineer’s posterior over the grid and accumulates expected counts:

n̄jk = Σi: j seen πik,   r̄jk = Σi: j seen πik xij,   πik ∝ wk ∏j seen Pj(qk)xij[1−Pj(qk)]1−xij(3)

and the M-step maximises, item by item, the expected complete-data log-likelihood Σk [ r̄jk log Pj(qk) + (n̄jk − r̄jk) log(1 − Pj(qk)) ] with weak priors on log a and b. We use Fisher scoring rather than Newton steps in the M-step; the observed Hessian includes a term that is not negative definite far from the optimum, and in our first implementation Newton steps drove discriminations to their lower bound. The expected Hessian has no such term. Convergence took 32 EM iterations.

Figure 00.10.20.30.43006001,2002,400Discrimination aDifficulty b
Root-mean-square error of recovered item discrimination and difficulty against calibration sample size. Mean of four simulated calibrations per size.

With 1,200 respondents, about 300 responses per item, the RMSE is 0.22 for discrimination and 0.19 for difficulty, on a scale where item difficulties have a standard deviation of 1. With 600 respondents it is 0.29 and 0.25; with 2,400, 0.17 and 0.14. We set 1,200 as the calibration target: below it, error in item parameters starts to compete with error in ability estimates, and the gain from going higher is modest.

Scoring: why percent correct is not good enough

Once items are calibrated, an engineer’s ability is estimated by its posterior mean (EAP), the expected value of θ over the posterior given their responses:

θ̂iEAP = Σk qk πik,   SEi = [ Σk qk2 πik − (θ̂iEAP)2 ]1/2(4)

The decisive test is alternate forms: give the same 500 simulated engineers two different booklets and ask how well the two scores agree. Percent correct agrees at 0.83; EAP at 0.87. The mean absolute gap between an engineer’s two scores, in standard deviations of the score, is 0.46 for percent correct and 0.41 for EAP. The improvement is real but modest at this booklet length, because the booklets were built to be balanced. It grows with every month a longitudinal study runs, since each month’s booklet will differ from the last by more than ours do from each other, and percent correct cannot correct for a harder month.

Adaptive testing

A fixed booklet wastes questions: a strong engineer answers easy items that tell us nothing, a struggling one answers hard items that tell us nothing either. A computerised adaptive test (CAT) chooses each next item to maximise information (2) at the current ability estimate, updates the posterior, and stops when the posterior standard deviation falls below a target or 40 items have been given.

Figure 08.7517.526.2535-3-2.5-2-1.5-1-0.500.511.522.53Whole bank (120 items)Best fixed 30-item form
Test information across ability for the whole calibrated bank and for the best fixed 30-item form, the 30 items most informative at the mean.
Figure 00.20.40.60.8010203040CAT, SE 0.40CAT, SE 0.30Best 30, fixedRandom 15mean items administeredRMSE of ability estimate
Mean items administered against RMSE of the ability estimate, for adaptive tests at four stopping rules and three fixed forms. 1,500 simulated engineers each.
DesignMean itemsRMSE of abilityRMSE where |θ| > 1.5
Adaptive, stop at SE 0.4010.80.42·
Adaptive, stop at SE 0.3515.30.37·
Adaptive, stop at SE 0.3022.90.340.41
Adaptive, stop at SE 0.2536.00.28·
Fixed: best 30 items at the mean300.320.50
Fixed: random 30 items300.360.52
Fixed: random 15 items150.510.67
Adaptive tests use randomesque selection from the five most informative items. Tail RMSE was computed for the 0.30 rule and the fixed forms only.

An adaptive test stopping at a standard error of 0.30 matches the accuracy of the best fixed 30-item form with 23 items on average, and is clearly better for engineers far from the mean (tail RMSE 0.41 against 0.50), where the fixed form’s information runs out. Stopping at 0.40 needs only 11 items and is still more accurate than a random 15-item form. For a monthly assessment inside a working week, that difference between 30 questions and 11 is the difference between a study engineers tolerate and one they quietly stop doing.

Exposure

Pure maximum-information selection has a cost that matters for a test given repeatedly to the same people: it reuses the same few highly discriminating items. Engineers talk, and an item everyone has seen measures memory, not comprehension.

Selection rule (SE 0.30 stop)Mean itemsRMSEMost-exposed itemItems shown to over halfItems never used
Maximum information22.50.32100%1621
Randomesque, top 523.00.3389%1618
Randomesque, top 1525.10.3273%173
Exposure rates over 1,500 simulated test-takers.

Randomesque selection from the fifteen best candidates costs about two extra items, does not hurt accuracy, cuts the most-exposed item from every test-taker to 73% and brings 18 unused items back into circulation. It does not reduce the core of 16 or 17 items seen by more than half of engineers. That needs a formal exposure ceiling in the style of Sympson and Hetter, and more good items in the middle of the scale, which is what we will write next.

Fairness: items that behave differently by language background

An item about a Python diff may be harder for an engineer who works mostly in Java for reasons unrelated to comprehension. That is differential item functioning (DIF): at equal ability, the probability of success differs by group. We simulate eight biased items, two each with a difficulty shift of 0.25, 0.4, 0.6 and 0.8 logits for a focal group making up 35% of respondents, re-drawn every replicate so that results average over item characteristics.

We screen with the Mantel-Haenszel procedure: stratify engineers by their score on the remaining items, and within each stratum s compare the odds of success in the reference and focal groups. With As, Bs the reference group’s correct and incorrect counts and Cs, Ds the focal group’s:

α̂MH = Σs (AsDs/Ns) / Σs (BsCs/Ns),   ΔMH = −2.35 ln α̂MH(5)

An item is flagged if |ΔMH| ≥ 1 and the continuity-corrected MH chi-square is significant at 5%, which is the ETS rule for moderate or large DIF.

Figure 0204060802.5%17.5%16.3%0.25 logit6.3%25%32.5%0.4 logit27.5%55%75%0.6 logit27.5%63.8%78.8%0.8 logit600 respondents1,2002,400
Share of biased items flagged, by size of the bias and number of respondents. 40 replicates of eight biased items each.

Detection depends heavily on sample size, because in a booklet design each item is seen by only a quarter of respondents and the focal group is a third of those. At 600 respondents only 28% of large (0.8-logit) biases are caught; at 2,400, 79%. Moderate biases of 0.4 logits are caught a third of the time even at 2,400. The false-positive rate stays near 3% throughout. The practical conclusion is uncomfortable: at the sample sizes a startup can reach in its first year, statistical DIF screening will miss most bias it should catch, so it must be backed by review. Every item will be read by engineers from at least two language backgrounds before it enters the bank, and items will be written in a language-neutral pseudocode where the concept allows, following the approach of the language-independent CS1 assessments.

The plan this sets

Method

Bank
120 items, six domains; log a ~ N(log 1.1, 0.35²), b ~ N(0, 1)
Design
16 blocks, 8 booklets of four blocks (29 to 31 items), each block in two booklets
Estimation
Bock-Aitkin EM, 41-point grid on [-4, 4], Fisher scoring M-step with priors log a ~ N(0, 0.5²), b ~ N(0, 2²)
Scoring
EAP with a standard normal prior on the same grid
CAT
Maximum information at the EAP estimate; minimum 5 items, maximum 40; randomesque k = 1, 5, 15
DIF
Mantel-Haenszel with 8 rest-score strata, ETS B/C rule, 40 replicates per sample size

Limitations

Simulated engineers answer exactly as the model says they will, so this study cannot reveal misfit, which is the most common way real calibrations fail. Comprehension is almost certainly not unidimensional: an engineer can read concurrency code well and error-handling code badly, and a single θ will average over that. Items about real diffs are also not locally independent when several are drawn from the same diff. Finally, all of this assumes the trait is stable within a test session, while our eventual interest is in how it changes month to month, which needs a longitudinal model on top of the measurement model.

Simulation only. No engineer has taken this test. Code, parameters and seeds are listed under Artefacts.

The 2PL model is Birnbaum’s [1], and Lord [2] and Embretson and Reise [3] are the standard references for its use. Marginal maximum likelihood estimation by EM is Bock and Aitkin [4]; EAP scoring is Bock and Mislevy [5]. Adaptive testing follows van der Linden and Glas [6]; randomesque selection is Kingsbury and Zara [7], and Sympson and Hetter [8] is the exposure-control method we plan to adopt. Mantel-Haenszel DIF screening is Holland and Thayer [9], with the ETS classification reviewed by Zwick [10]. In computing education, Lister and colleagues [11] showed that tracing and reading are separable from writing, which motivates our item types, and Tew and Guzdial [12] and Parker and colleagues [13] built and validated language-independent assessments, which is the route we take to reduce language-background bias at source.

Artefacts

Everything below is published or available on request. A number nobody can reproduce is an advertisement, not a result.

Codeawl_2023_01_irt.pyBank generator, booklet design, Bock-Aitkin EM, EAP, CAT, MH DIF · Python, MIT
Dataawl_2023_01.jsonResults file, every number quoted in this paper

References

  1. Birnbaum, A. (1968). Some Latent Trait Models and Their Use in Inferring an Examinee’s Ability. In Lord, F. M., & Novick, M. R., Statistical Theories of Mental Test Scores. Addison-Wesley.
  2. Lord, F. M. (1980). Applications of Item Response Theory to Practical Testing Problems. Lawrence Erlbaum.
  3. Embretson, S. E., & Reise, S. P. (2000). Item Response Theory for Psychologists. Lawrence Erlbaum.
  4. Bock, R. D., & Aitkin, M. (1981). Marginal Maximum Likelihood Estimation of Item Parameters: Application of an EM Algorithm. Psychometrika, 46(4).
  5. Bock, R. D., & Mislevy, R. J. (1982). Adaptive EAP Estimation of Ability in a Microcomputer Environment. Applied Psychological Measurement, 6(4).
  6. van der Linden, W. J., & Glas, C. A. W. (Eds.) (2010). Elements of Adaptive Testing. Springer.
  7. Kingsbury, G. G., & Zara, A. R. (1989). Procedures for Selecting Items for Computerized Adaptive Tests. Applied Measurement in Education, 2(4).
  8. Sympson, J. B., & Hetter, R. D. (1985). Controlling Item-Exposure Rates in Computerized Adaptive Testing. Proceedings of the 27th Annual Meeting of the Military Testing Association.
  9. Holland, P. W., & Thayer, D. T. (1988). Differential Item Performance and the Mantel-Haenszel Procedure. In Wainer, H., & Braun, H. I. (Eds.), Test Validity. Lawrence Erlbaum.
  10. Zwick, R. (2012). A Review of ETS Differential Item Functioning Assessment Procedures. ETS Research Report RR-12-08.
  11. Lister, R., Adams, E. S., Fitzgerald, S., et al. (2004). A Multi-National Study of Reading and Tracing Skills in Novice Programmers. ITiCSE Working Group Reports.
  12. Tew, A. E., & Guzdial, M. (2011). The FCS1: A Language Independent Assessment of CS1 Knowledge. SIGCSE.
  13. Parker, M. C., Guzdial, M., & Engleman, S. (2016). Replication, Validation, and Use of a Language Independent CS1 Knowledge Assessment. ICER.
Cite this work

Bhardwaj, M. (2023). An item bank for code comprehension: calibration, adaptive testing and fairness checks with item response theory. AI Work Lab Research, AWL-2023-01.

Mohit Bhardwaj

Head of Research · aiworklab

Mohit led AI Work Lab’s research programme from January 2023 to March 2025: the comprehension item bank, the statistics of code-model leaderboards, review-state telemetry, variance in agent evaluations, and the design of the twelve-month cohort study that the Measurement team went on to run.