Skip to content
SlateGitOrgPublic

About

An exam item-analysis workbook with live formulas that exposes a miskeyed question by its negative item-rest correlation, recalculated in CI and matched to a NumPy reference.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

miskey

CI

miskey

miskey builds an exam item-analysis workbook in which every statistic is a live Excel formula, and uses it to find a miskeyed question. A miskeyed item shows up as a negative item-rest correlation: the students who chose the published key are mostly the weak ones, while the strong students pile onto another option. Each statistic is computed twice, as an Excel formula in the .xlsx and as NumPy code, and the test suite recalculates the saved workbook with an independent formula engine and requires the two to agree to 1e-9. The data is synthetic: a seeded two-parameter logistic (2PL) exam of 200 students by 25 four-option items with four planted problems.

The problem

Assessment and institutional-research analysts at a college run item analysis in Excel after every exam. Hand-built workbooks tend to fail in three ways:

  • They report the item-total correlation. The item is part of the total it is correlated with, so every item looks better than it is, and a single miskeyed item can still look acceptable.
  • They paste values instead of formulas, so correcting an answer key changes nothing until someone rebuilds the sheet.
  • They miss the one miskeyed question that quietly costs the strongest students a mark.

miskey fixes the statistic (item-rest correlation, with the item removed from the total), keeps every cell live so that editing one key cell recalculates everything, and checks the formulas against a reference implementation instead of trusting them.

How it works

flowchart LR
    G["IRT response generator<br/>2PL, 4 options, 2% omitted<br/>seeded"] --> L["Answer letters<br/>and published key"]
    L --> R["NumPy reference<br/>p, r_it, r_rest, D, KR-20,<br/>alpha-if-deleted, flags"]
    L --> W["openpyxl workbook<br/>live formulas on Responses,<br/>Key, Scores, ItemStats,<br/>Distractors, Summary"]
    W --> E["formulas engine<br/>recalculates the saved file"]
    E --> C{"Compare every cell<br/>with the reference<br/>to 1e-9"}
    R --> C
    C --> F["Flags: miskey_suspect,<br/>too_easy, too_hard,<br/>weak, ambiguous"]
    F --> K["rekey: change one Key cell,<br/>recalculate, compare<br/>before and after"]
    K --> W
Loading

The workbook has seven sheets. Responses holds the raw letters (X for an omitted answer, never a blank). Key holds the answer key and a unit label per item; its yellow cells are the only ones a user edits. Scores computes each student's total as a SUMPRODUCT of the response row against the key row, and assigns the upper or lower 27% group. ItemStats has one row per item: difficulty p, the mean totals M1 and M0 of students who got the item right and wrong (AVERAGEIF), the item-total correlation r_it, the item-rest correlation r_rest, the upper-lower discrimination D, alpha-if-item-deleted and five flags. Distractors counts each option overall and in each group with COUNTIF and COUNTIFS. Summary has N, k, mean, SD, KR-20, SEM and the group cut-offs. Notes explains the formulas. Ranges are named (Totals, Groups, KeyRow, ItemP, ...) and the flag cells carry conditional formatting.

Every statistic is a short closed-form formula with population variances throughout:

r_it   = (M1 - M0) / sigma_t * sqrt(p*q)
r_rest = (r_it*sigma_t - sigma_i) / sqrt(sigma_t^2 + sigma_i^2 - 2*r_it*sigma_i*sigma_t)
alpha_if_deleted = (k-1)/(k-2) * (1 - (sum(pq) - p_i*q_i) / (sigma_t^2 + sigma_i^2 - 2*r_it*sigma_i*sigma_t))
KR-20  = k/(k-1) * (1 - sum(pq) / sigma_t^2)
SEM    = sigma_t * sqrt(1 - KR-20)

The flags:

Flag Rule
miskey_suspect r_rest < 0 and some option other than the key is chosen by more of the upper group than the key is
too_easy p > 0.95
too_hard p < 0.20
weak r_rest < 0.15
ambiguous a distractor is chosen by a larger share of the upper group than of the lower group

The upper and lower groups are the students at or above the 73rd and at or below the 27th percentile of the totals (PERCENTILE.INC in Excel, numpy.percentile(method="linear") in the reference).

Quick start

Python 3.11 or newer.

python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"

miskey generate --out data                 # seeded responses.csv, key.csv, truth.csv
miskey build --data data --out item_analysis.xlsx
miskey analyze --data data                 # item table and flags from the NumPy reference
miskey verify --workbook item_analysis.xlsx
miskey rekey --item 17 --key C --workbook item_analysis.xlsx

build and analyze also run without --data; they then generate the same default exam (--students 200 --items 25 --seed 2026). rekey writes the corrected copy next to the original as item_analysis_rekeyed.xlsx; pass --out to choose another path. Open the workbook in Excel and edit a yellow cell on Key to watch the statistics change; the file stores no cached values, so Excel calculates it on open.

Example output

miskey analyze, run on the seeded exam (200 students, 25 items, seed 2026):

                                        Item analysis                                        
 item ┃ key ┃     p ┃   r_it ┃ r_rest ┃      D ┃ alpha_del ┃ flags                           
━━━━━━╇━━━━━╇━━━━━━━╇━━━━━━━━╇━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 Q1   │ A   │ 0.430 │  0.511 │  0.432 │  0.660 │     0.819 │                                 
 Q2   │ B   │ 0.600 │  0.553 │  0.479 │  0.647 │     0.817 │                                 
 Q3   │ B   │ 0.490 │  0.450 │  0.365 │  0.572 │     0.822 │                                 
 Q4   │ D   │ 0.360 │  0.563 │  0.492 │  0.667 │     0.816 │                                 
 Q5   │ B   │ 0.970 │  0.162 │  0.128 │  0.056 │     0.828 │ too_easy, weak                  
 Q6   │ C   │ 0.195 │  0.504 │  0.441 │  0.492 │     0.819 │ too_hard                        
 Q7   │ D   │ 0.555 │  0.635 │  0.570 │  0.807 │     0.813 │                                 
 Q8   │ A   │ 0.725 │  0.423 │  0.346 │  0.442 │     0.823 │                                 
 Q9   │ D   │ 0.265 │  0.097 │  0.009 │  0.055 │     0.835 │ weak, ambiguous                 
 Q10  │ C   │ 0.550 │  0.613 │  0.545 │  0.776 │     0.814 │                                 
 Q11  │ A   │ 0.775 │  0.561 │  0.500 │  0.547 │     0.817 │                                 
 Q12  │ A   │ 0.715 │  0.553 │  0.485 │  0.591 │     0.817 │                                 
 Q13  │ D   │ 0.650 │  0.569 │  0.498 │  0.663 │     0.816 │                                 
 Q14  │ D   │ 0.210 │  0.432 │  0.362 │  0.388 │     0.822 │ ambiguous                       
 Q15  │ A   │ 0.735 │  0.478 │  0.405 │  0.498 │     0.820 │                                 
 Q16  │ C   │ 0.840 │  0.438 │  0.375 │  0.333 │     0.822 │                                 
 Q17  │ B   │ 0.245 │ -0.210 │ -0.290 │ -0.194 │     0.846 │ miskey_suspect, weak, ambiguous 
 Q18  │ A   │ 0.425 │  0.538 │  0.461 │  0.661 │     0.818 │                                 
 Q19  │ A   │ 0.345 │  0.423 │  0.340 │  0.497 │     0.823 │                                 
 Q20  │ D   │ 0.670 │  0.446 │  0.366 │  0.558 │     0.822 │                                 
 Q21  │ C   │ 0.225 │  0.547 │  0.484 │  0.590 │     0.817 │                                 
 Q22  │ A   │ 0.425 │  0.130 │  0.031 │  0.068 │     0.836 │ weak, ambiguous                 
 Q23  │ D   │ 0.500 │  0.526 │  0.447 │  0.652 │     0.818 │                                 
 Q24  │ C   │ 0.205 │  0.469 │  0.402 │  0.424 │     0.821 │                                 
 Q25  │ A   │ 0.485 │  0.501 │  0.421 │  0.618 │     0.819 │                                 
    Summary     
 N     │    200 
 k     │     25 
 mean  │  12.59 
 SD    │  4.983 
 KR-20 │ 0.8278 
 SEM   │  2.068 

Item 17 is flagged miskey_suspect: its item-rest correlation is -0.290. The Distractors sheet shows why. Of the 61 students in the upper group, 48 chose C and 7 chose B, the published key; among the 55 students in the lower group, B was chosen by 17 and C by 20. The item was written with answer C. The other flags are also what the data contains: Q5 is too easy and barely separates students (p = 0.970, D = 0.056), Q9 is the guessing item (r_rest = 0.009), and Q22 has a distractor that stronger students prefer. Q6 is simply hard. Q14 is flagged ambiguous by chance, and Q17 is also ambiguous because C, the true answer, is by the published key a distractor that the upper group prefers.

miskey verify recalculates the saved workbook with the formulas engine and compares every ItemStats, Summary, Scores and Distractors cell with the reference:

ok: every ItemStats, Summary, Scores and Distractors cell matches the reference (largest difference 
4.4e-16, tolerance 1e-09)
    Summary     
 N     │    200 
 k     │     25 
 mean  │  12.59 
 SD    │  4.983 
 KR-20 │ 0.8278 
 SEM   │  2.068 

miskey rekey --item 17 --key C edits the single key cell, recalculates, and prints before and after:

                     Item 17: key B -> C                     
                  ┃                          before ┃  after 
━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━
 key              │                               B │      C 
 p                │                           0.245 │  0.545 
 r_it             │                          -0.210 │  0.480 
 r_rest           │                          -0.290 │  0.403 
 D                │                          -0.194 │  0.601 
 alpha_if_deleted │                           0.846 │  0.846 
 flags            │ miskey_suspect, weak, ambiguous │   none 
 KR-20            │                          0.8278 │ 0.8511 
 SEM              │                           2.068 │  2.050 
largest change in any other item's p: 0.0e+00
wrote item_analysis_rekeyed.xlsx

Correcting that one cell turns r_rest from -0.290 to 0.403, clears every flag on the item, raises KR-20 from 0.8278 to 0.8511 and leaves the difficulty of every other item untouched. The alpha-if-deleted value for item 17 is the same before and after (0.846) because it is the reliability of the other 24 items; KR-20 sat below it while the bad key was in place (keeping the item hurt) and sits above it afterwards.

Design decisions

  1. Closed-form formulas instead of a scored matrix. The workbook has no 200 x 25 grid of 0/1 scores. r_it comes from the AVERAGEIF means M1 and M0, and r_rest and alpha-if-deleted come from the variance identity var(total - item) = sigma_t^2 + sigma_i^2 - 2*r_it*sigma_i*sigma_t. Each statistic is one short formula and the file stays small, at the cost of formulas that lean on an identity a reader has to trust. The tests check the identity against brute-force recomputation with each item removed, and the Notes sheet states it.
  2. Item-rest correlation, plus distractor evidence, for the miskey flag. r_it includes the item in its own total and is biased upward; r_rest removes it. A negative r_rest alone also occurs for a pure-guessing item, so miskey_suspect additionally requires that another option beat the key in the upper group. The strict comparison means a key that ties for most-chosen is not flagged. A pure-guessing item can still trip the flag on some seeds, by chance.
  3. Omitted answers are stored as X. A blank cell is matched differently by Excel and by formula engines in COUNTIF criteria; a letter behaves the same everywhere. X scores 0 and is counted in the distractor tables, so an omission is treated as wrong, which is the usual scoring rule but means p does not separate "left blank" from "answered wrongly".
  4. Population variances throughout. KR-20 is defined with the variance of the totals, and the identities above are exact only when every variance is the population one, so the workbook uses STDEV.P (not Excel's default STDEV.S) for the totals, sqrt(p*q) for the items, and the reference uses numpy.std with ddof=0. Mixing the two conventions is a common slip in hand-built workbooks and moves KR-20, SEM and r_rest by small, hard-to-spot amounts.
  5. An independent formula engine in the loop, with a function allow-list. The formulas package implements a subset of Excel, so the workbook uses only SUMPRODUCT, COUNTIF, COUNTIFS, AVERAGEIF, SUM, SQRT, IF, AND, OR, MAX, COUNT, COUNTA, AVERAGE, STDEV.P and PERCENTILE.INC (the last two with the _xlfn. prefix Excel expects), and a test checks every function in the file against both the list and the engine's registry. That keeps the workbook honest but rules out nicer constructs; for instance SUMPRODUCT(--(a=b)) returns 0 in the engine, so the score formula multiplies by 1 instead. The engine is not Excel, so agreement is strong evidence rather than proof of what Excel displays.
  6. Groups by cut-off, not by rank. Upper and lower groups are defined by comparing each total with the percentile cut-offs, so tied totals fall in the same group and group sizes vary (61 and 55 here, not 54 and 54). That is how the Excel formulas can express it without sorting, and the reference does the same; classical 27% tables sort and split instead.

Testing

pytest -q
ruff check .
ruff format --check .

81 tests run offline in about 20 seconds. The seeded workbook is recalculated once per test session (a session-scoped fixture) and once more for the rekey test; a few small workbooks (the 6-student hand fixture, a degenerate item, a flat score distribution, the CLI tests) are recalculated separately.

  • Hand fixture: 6 students by 4 items scored 1111, 1110, 1100, 1010, 0100, 0000. KR-20 = 0.6667, r_it = [0.8216, 0.5477, 0.7746, 0.6928] and r_rest = [0.6250, 0.2132, 0.5222, 0.4889], checked to 1e-4 in the reference and in the recalculated workbook.
  • Seeded exam: every ItemStats and Summary cell (plus Scores and Distractors) of the recalculated workbook equals the reference to 1e-9; r_it equals numpy.corrcoef(item, total); closed-form r_rest and alpha-if-deleted equal brute-force recomputation with the item removed.
  • Planted problems: item 17 is the only miskey_suspect item; item 5 is too_easy, item 9 weak and item 22 ambiguous; after rekey --item 17 --key C item 17 has r_rest above 0.25 and no flag, KR-20 rises by more than 0.01 and no other item's p moves.
  • Workbook structure: every ItemStats and Summary value cell is a formula, Responses has no blank cells, every function used is on the allow-list and in the engine's registry, defined names and conditional formatting are present.
  • Degenerate input: an item everybody answers correctly yields blank correlations rather than an error, and a flat score distribution is reported as a #DIV/0! rather than hidden.

Project layout

.
├── pyproject.toml
├── src/miskey/
│   ├── synth.py       # seeded 2PL generator with the planted problems
│   ├── reference.py   # NumPy reference statistics and flags
│   ├── workbook.py    # openpyxl builder: sheets, live formulas, names, formatting
│   ├── recalc.py      # recalculate with `formulas`, compare with the reference
│   ├── rekey.py       # edit one key cell, recalculate, report before and after
│   ├── dataio.py      # CSV input/output and reading a built workbook back
│   └── cli.py         # `miskey` command
├── tests/
└── .github/workflows/ci.yml

License

MIT. See LICENSE.

About

An exam item-analysis workbook with live formulas that exposes a miskeyed question by its negative item-rest correlation, recalculated in CI and matched to a NumPy reference.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages