Skip to content

feat(experimentation): Bayesian stats kernel#7769

Draft
gagantrivedi wants to merge 1 commit into
mainfrom
feat/experiment-stats-kernel
Draft

feat(experimentation): Bayesian stats kernel#7769
gagantrivedi wants to merge 1 commit into
mainfrom
feat/experiment-stats-kernel

Conversation

@gagantrivedi

@gagantrivedi gagantrivedi commented Jun 12, 2026

Copy link
Copy Markdown
Member
  • I have read the Contributing Guide.
  • I have added information to docs/ if required so people know about the feature. (deferred — internal module; docs land with the results UI.)
  • I have filled in the "Changes" section below.
  • I have filled in the "How did you test this code" section below.

Changes

Contributes to the experimentation results scorecard (v0.2). Pure stats module — no Django, ClickHouse or schema changes; the query, model and endpoints follow in stacked PRs.

  • VariantStats — per-variant sufficient statistics (n, sum, sum_squares) with derived mean and clamped unbiased variance; the only data the warehouse needs to return per metric × variant.
  • compare_to_control(control, treatment) — relative lift with delta-method variance, Normal posterior under a flat prior: 95% credible interval and chance_to_win = P(lift > 0); direction flips for "lower is better" metrics belong to the payload builder. Returns None when inference is undefined (an arm below two observations, or zero control mean); zero variance degenerates to certainty without dividing by zero.
  • srm_p_value(observed, expected_shares) — chi-squared goodness-of-fit survival, exact for integer degrees of freedom using only the stdlib (erfc base case + the incomplete-gamma recurrence; no scipy). None when not computable.

How did you test this code?

  • 19 example-based tests: hand-derived proportions case (lift/CI/chance to 1e-4), identical arms, zero-variance degenerate certainty, undefined-inference inputs, chi-squared reference values for 1, 2 and 3 dof (0.0455, e⁻¹, 0.04601), heavy imbalance below the 0.001 threshold, non-computable SRM inputs, variance clamping.
  • pytest tests/unit/experimentation/ — 265 passed; ruff + mypy strict clean.

@github-actions github-actions Bot added the api Issue related to the REST API label Jun 12, 2026
@vercel

vercel Bot commented Jun 12, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

3 Skipped Deployments
Project Deployment Actions Updated (UTC)
docs Ignored Ignored Preview Jun 12, 2026 9:01am
flagsmith-frontend-preview Ignored Ignored Preview Jun 12, 2026 9:01am
flagsmith-frontend-staging Ignored Ignored Preview Jun 12, 2026 9:01am

Request Review

@github-actions github-actions Bot added the feature New feature or request label Jun 12, 2026
@gagantrivedi gagantrivedi force-pushed the feat/experiment-stats-kernel branch from c406904 to 16e699b Compare June 12, 2026 08:11
@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels Jun 12, 2026
@gagantrivedi gagantrivedi force-pushed the feat/experiment-stats-kernel branch from 16e699b to 79af371 Compare June 12, 2026 08:14
@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels Jun 12, 2026
@codecov

codecov Bot commented Jun 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.56%. Comparing base (879046c) to head (a8ba0c8).

Additional details and impacted files
@@           Coverage Diff            @@
##             main    #7769    +/-   ##
========================================
  Coverage   98.56%   98.56%            
========================================
  Files        1459     1461     +2     
  Lines       56134    56237   +103     
========================================
+ Hits        55327    55430   +103     
  Misses        807      807            

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@gagantrivedi gagantrivedi force-pushed the feat/experiment-stats-kernel branch from 79af371 to a8ba0c8 Compare June 12, 2026 09:01
@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Issue related to the REST API feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant