Skip to content

[Repo Assist] Implement InvCDF for Beta, F, and StudentT distributions (closes part of #262)#365

Draft
github-actions[bot] wants to merge 2 commits intodeveloperfrom
repo-assist/fix-issue-262-invcdf-beta-f-studentt-60883adc61955ac8
Draft

[Repo Assist] Implement InvCDF for Beta, F, and StudentT distributions (closes part of #262)#365
github-actions[bot] wants to merge 2 commits intodeveloperfrom
repo-assist/fix-issue-262-invcdf-beta-f-studentt-60883adc61955ac8

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions bot commented Apr 2, 2026

🤖 This is an automated PR from Repo Assist.

Problem

Three continuous distributions had failwithf "InvCDF not implemented yet" stubs (and F had a commented-out partial implementation), making quantile computation completely unavailable. This is part of the broader issue #262 (Inverse CDF of distributions).

Remaining stubs addressed by this PR:

  • Beta.InvCDF — no closed form in general
  • F.InvCDF — no closed form; relates to the Beta distribution
  • StudentT.InvCDF — no closed form; relates to the Beta distribution

Approach

Beta.InvCDF

Newton–Raphson iteration starting from the mean (α/(α+β)), clamped to (ε, 1−ε) to stay in the valid domain. Uses Beta.PDF as the derivative. Fallback to Rootfinding.Brent.tryFindRootWith if the Newton–Raphson residual is too large (handles edge cases like very small/large parameter values).

Closed-form special cases handled exactly:

  • α=1, β=1 → Uniform: InvCDF(p) = p
  • β=1InvCDF(p) = p^(1/α)
  • α=1InvCDF(p) = 1 − (1−p)^(1/β)

F.InvCDF

Derived analytically from Beta.InvCDF using the relationship between the F and Beta CDFs:

F(d₁,d₂).CDF(x) = I_u(d₁/2, d₂/2)  where u = d₁x/(d₂ + d₁x)
→  u = Beta.InvCDF(d₁/2, d₂/2, p)
→  x = d₂ · u / (d₁ · (1 − u))
```

### StudentT.InvCDF
Derived analytically from Beta.InvCDF using the regularised incomplete beta representation of the StudentT CDF:
```
CDF(x) = 0.5 · I_h(ν/2, 1/2)  for x ≤ μ,  where h = ν/(ν + ((x−μ)/τ)²)
→  h = Beta.InvCDF(ν/2, 1/2, 2p)
→  k = −√(ν·(1−h)/h)
→  x = μ + τ·k
For p > 0.5: use symmetry about μ

No new dependencies introduced; all three implementations rely only on the existing Beta.CDF, Beta.PDF, and Rootfinding.Brent already present in the library.

Test Status

22 new regression tests added covering:

  • Boundary values (p=0, p=1)
  • Exact closed-form cases (Uniform, Beta(2,1), Beta(1,2))
  • Symmetry checks (StudentT median = μ, StudentT InvCDF(p) = −InvCDF(1−p))
  • R-verified quantiles: qt(0.975, 10) = 2.228139, qf(0.95, 3, 4) = 6.5914
  • CDF(InvCDF(p)) ≈ p round-trip checks for various parameters

✅ Build: succeeded (7 pre-existing warnings, 0 errors)
✅ Tests: 1,216/1,216 passed (0 failures — all pre-existing tests still pass)

Remaining work for #262

After this PR, the remaining InvCDF stubs are:

  • Gamma.InvCDF — already implemented (Newton–Raphson, present in the codebase)
  • Normal.InvCDF — already implemented (Wichura algorithm)
  • LogNormal.InvCDF — derived from Normal
  • MultivariateNormal.InvCDF — complex, not yet addressed
  • StudentizedRange.InvCDF — requires numerical integration, not yet addressed

Generated by 🌈 Repo Assist, see workflow run. Learn more.

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@e1ecf341a90b7bc2021e77c58685d7e269e20b99

… of #262

- Beta.InvCDF: Newton-Raphson with mean initialisation, Brent fallback
  Handles boundary cases (p=0/1) and closed-form cases (alpha=1, beta=1)
- F.InvCDF: derived analytically from Beta.InvCDF via
    u = Beta.InvCDF(d1/2, d2/2, p);  x = d2*u / (d1*(1-u))
- StudentT.InvCDF: derived analytically from Beta.InvCDF via the
  regularised incomplete beta relationship; uses symmetry for p > 0.5
- 22 new tests: boundary checks, exact closed-form cases, R-verified
  quantiles, and CDF(InvCDF(p))=p round-trips; all 1216 tests pass

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants