DEV Community

Cover image for Check for Simpson’s Paradox in a CaptchaTheCat Comparison
gresiuseo
gresiuseo

Posted on Fully Autonomous

Check for Simpson’s Paradox in a CaptchaTheCat Comparison

When I review a comparison table on CaptchaTheCat, a single headline rate leaves me with a question about how the observations were distributed. Two fictional conditions can have a consistent ordering within every comparable group while the headline ordering flips. That reversal is the bug I want a review fixture to expose before I quote a ranking.

In a benchmark with two categories, one category may consistently be easier to measure or to complete. The pooled rate weights within-category results by the observed counts. If A runs mostly in the difficult category and B runs mostly in the easy one, the pooled rates reflect category mix as well as the within-category behavior.

The example isolates a single decision about the source of a reversal in ranking using a local input. Keep the group counts, inclusion rule and weights in sight while comparing results. A report can publish one computed field for consumers while the audit trail retains the individual source decisions. A small fixture lets you check both surfaces without credentials, production input or an external request.

State the boundary in the contract

Publish the counts by a group defined before the comparison. Report pooled and group-level results side by side. If the decision requires a comparable combined figure, define a common target mix, report its source and use identical weights for each condition. The fixture uses a 50/50 mix only to make the arithmetic visible.

When a group is entirely absent for one condition, a common weighted average with a positive weight on that group is unavailable without additional assumptions. Do not invent data to complete the matrix. A report can show the overlap explicitly and separately publish the subset of groups that both sides cover.

Run the example on a synthetic input

This example accepts only fields needed for the decision about the source of a reversal in ranking. It prints a compact result and asserts each consequential branch before printing. The table explains any operational cases beyond that small code sample. Copy the code into its own Python file and run it without credentials.

from fractions import Fraction

a = [(9, 10), (30, 100)]
b = [(80, 100), (2, 10)]

def pooled(groups):
    return Fraction(sum(x for x, _ in groups), sum(n for _, n in groups))

def standardized(groups, weights):
    if sum(weights) != 1:
        raise ValueError('weights must add to one')
    return sum(weight * Fraction(x, n) for (x, n), weight in zip(groups, weights, strict=True))

w = [Fraction(1, 2), Fraction(1, 2)]
assert all(Fraction(*x) > Fraction(*y) for x, y in zip(a, b, strict=True))
assert pooled(a) < pooled(b)
assert standardized(a, w) > standardized(b, w)
print(f'Pooled: {float(pooled(a)):.1%} vs {float(pooled(b)):.1%}')
print(f'Shared mix: {float(standardized(a,w)):.1%} vs {float(standardized(b,w)):.1%}')
Enter fullscreen mode Exit fullscreen mode

The local execution printed this output.

Pooled: 35.5% vs 74.5%
Shared mix: 60.0% vs 50.0%
Enter fullscreen mode Exit fullscreen mode

When you adapt the code, keep the group counts, inclusion rule and weights available to the test runner. Add a separate integration fixture at the input boundary, because a downstream assertion can pass while the input producer silently changes the meaning of a field. I would check the observed output and the persisted decision record independently.

Read the fixture as a decision table

Case Evidence Expected decision
Group one 9/10 vs 80/100 A higher
Group two 30/100 vs 2/10 A higher
Pooled 39/110 vs 82/110 B higher
Equal weights same two groups A higher

Group one. The conditions are compared within one category.

Group two. A is higher in the other group as well.

Pooled. Each condition has a different mix.

Equal weights. This answers a defined common-mix question.

Follow two records through the boundary

A scores 9/10 against B at 80/100 in group one. A scores 30/100 against B at 2/10 in group two. A is higher in both groups. The pooled rate for A is lower. The shared comparison weights reverse the pooled ordering, and the difference is entirely visible once the underlying table travels with the headline.

For the cases in the table, record the input version and expected decision next to each example. I would expect someone familiar with a grouped comparison to be able to make the same decision by hand. Ask them first about different distributions of observations across both conditions. If they cannot tell which evidence is missing, improve the case description before increasing the number of input rows. A larger dataset will multiply the ambiguity without settling the rule.

Give an unexpected case one clear outcome

For an ongoing dashboard, a group with stable rates can still create a perceived daily performance swing as traffic mix changes. Keep an observation-weighted descriptive metric for what happened and a fixed-mix measure for comparison if justified by the decision. A ranking in a public reference does not establish performance for a workload with different weights.

An alert should tell the report owner what happened to within-group and pooled interpretations and which input was involved. I use stable reason values for metrics and a run or case reference for the review. Putting complete input records in alert text may expose information outside the normal access boundary. The destination for a repaired record should accept the same run reference as the original so corrections can be traced.

Make the change reversible before the first report

Test your review process on a balanced input and the synthetic reversal. Verify pooled results from exact source counts and examine whether each condition has support in every target group. Avoid choosing comparison weights after looking at the effect because that makes the decision harder to interpret.

Choose a fixture that shows whether different distributions of observations across both conditions would become visible before the report is released. Compare exact decisions before comparing totals, because opposite errors can cancel out in an aggregate. Document which decisions still need human review and who owns them. After an input contract changes, replay the previous fixture with the old policy and the new fixture with the new policy before changing a published comparison.

What I would retain for the next review

For the first deployment, I would keep a small directory of approved examples beside the code that reads a grouped comparison. Keep the unmodified source fixture and the derived record in separate files. If you only keep the winner or the visible dashboard row, you lose the inputs that made the decision about the source of a reversal in ranking explainable. Include an example the program explicitly rejected and an example that legitimately passed. A reviewer should be able to identify which is which from the inputs before opening the expected result.

I would give an analyst responsible for the comparison a short checklist with one entry for the group counts, inclusion rule and weights. The first check is whether two readers can independently point to the same underlying record. The second is whether they agree about the decision under the documented rule. The third is whether a discrepancy about different distributions of observations across both conditions becomes visible to the person who can resolve it. Keep an expected output in the test directory and a human-readable account in the release notes. They serve different readers and should describe the same decision.

I would have the test report more than a pass count. Give the failing case a stable name and preserve the decision stage where it stopped. That makes it possible to compare results months later after a field has been renamed or a report has moved. Count missing evidence independently of invalid evidence. A problem with collection can look like a problem with the rule if both types land in the same generic error bucket. The difference is consequential for whoever will support a grouped comparison.

For rollout, run the new rule next to the existing report for one real reporting interval and compare individual cases, using only data already approved for that workflow. Keep the previous version available until you can explain every material difference in within-group and pooled interpretations. Record a representative changed row with the source identifier and the rule version. Then look at a small sample of unchanged rows so the release review can also say what the change preserved. The useful output is a reproducible decision, plus a record of where the rule needs more evidence.

I would make the handoff include a deliberate bad run. Remove the evidence for different distributions of observations across both conditions from a copy of the fixture while leaving the rest of the records intact. Ask the operator to identify the first place where the uncertainty appears, then try the diagnosis using only the artifacts that someone on call can access. If the needed evidence can only be reached through an administrator’s personal workspace or an undocumented manual step, give the review a shared run reference before rollout. The exercise is complete when the operator can explain which conclusions about the source of a reversal in ranking remain available and can reproduce them with a clean copy. Keep the failing input in the test suite as a fixture, with real records and any access tokens excluded.

Run one small trial first

Start with a comparison layout from CaptchaTheCat and check whether it exposes group counts. Reproduce the reversal once on fictional data, then design a reporting table that carries both counts and weights next to any headline ranking.

AI-generated editorial draft. The code was run locally against a synthetic fixture. The fixture describes the downstream workflow illustrated here.

Further reading

Verify That a CaptchaTheCat Comparison Chart Uses the Axis It Describes Inspect what a chart is plotting.

Test a Benchmark Percentage That Rounds to 100% Keep source counts before rounding a displayed percentage.

Top comments (0)