[Stack 13/17] Fix D6: match Clojure two-proportion test formula (+1 pseudocount)#2520
Open
jucor wants to merge 1 commit intospr/edge/48b77ba3from
Open
[Stack 13/17] Fix D6: match Clojure two-proportion test formula (+1 pseudocount)#2520jucor wants to merge 1 commit intospr/edge/48b77ba3from
jucor wants to merge 1 commit intospr/edge/48b77ba3from
Conversation
This was referenced Mar 30, 2026
Open
Open
f593bae to
cd39374
Compare
d92e3f2 to
be320d5
Compare
## Summary The Python `two_prop_test` used a standard two-proportion z-test with no pseudocounts, while Clojure's `stats/two-prop-test` (stats.clj:18-33) adds +1 to all four inputs (`succ-in`, `succ-out`, `pop-in`, `pop-out`) via `(map inc ...)` before computing the pooled z-test. This Laplace smoothing regularizes z-scores for small group sizes, which are common in Polis conversations. ## Changes - **Signature change**: `two_prop_test(p1, n1, p2, n2)` (proportions) → `two_prop_test(succ_in, succ_out, pop_in, pop_out)` (raw counts) - **Formula**: Standard pooled z-test on pseudocount-adjusted values: `pi1 = (succ_in+1)/(pop_in+1)`, `pi_hat = (s1+s2)/(p1+p2)` - **Callers updated**: Both scalar (`add_comparative_stats`) and vectorized (`compute_group_comment_stats_df`) now pass raw counts matching Clojure's `(stats/two-prop-test (:na in-stats) (sum :na rest-stats) (:ns in-stats) (sum :ns rest-stats))` (repness.clj:97-100) ## Affected output fields - `rat` (agree representativeness test z-score) - `rdt` (disagree representativeness test z-score) - `agree_metric`, `disagree_metric` (downstream of rat/rdt) ## Test plan - [x] Targeted D6 tests pass (formula, edge cases, regularization effect) - [x] Full test suite passes (excluding DynamoDB/MinIO tests) - [x] Private dataset tests pass (--include-local) - [x] Golden snapshots re-recorded for all 7 datasets 🤖 Generated with [Claude Code](https://claude.com/claude-code) ## Squashed commits - RED: add D6 blob injection test (two_prop_test vs Clojure repness-test) - Fix D6: match Clojure two-proportion test formula (+1 pseudocount) - Plan: add D6 PR number and stack position to cross-reference commit-id:23c03d70
be320d5 to
c30ab91
Compare
Delphi Coverage Report
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The Python
two_prop_testused a standard two-proportion z-test with no pseudocounts,while Clojure's
stats/two-prop-test(stats.clj:18-33) adds +1 to all four inputs(
succ-in,succ-out,pop-in,pop-out) via(map inc ...)before computingthe pooled z-test. This Laplace smoothing regularizes z-scores for small group sizes,
which are common in Polis conversations.
Changes
two_prop_test(p1, n1, p2, n2)(proportions) →two_prop_test(succ_in, succ_out, pop_in, pop_out)(raw counts)pi1 = (succ_in+1)/(pop_in+1),pi_hat = (s1+s2)/(p1+p2)add_comparative_stats) and vectorized(
compute_group_comment_stats_df) now pass raw counts matching Clojure's(stats/two-prop-test (:na in-stats) (sum :na rest-stats) (:ns in-stats) (sum :ns rest-stats))(repness.clj:97-100)
Affected output fields
rat(agree representativeness test z-score)rdt(disagree representativeness test z-score)agree_metric,disagree_metric(downstream of rat/rdt)Test plan
🤖 Generated with Claude Code
Squashed commits
commit-id:23c03d70
Stack: