[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
Conversation
… 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>
14 tasks
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.
🤖 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 generalF.InvCDF— no closed form; relates to the Beta distributionStudentT.InvCDF— no closed form; relates to the Beta distributionApproach
Beta.InvCDF
Newton–Raphson iteration starting from the mean (
α/(α+β)), clamped to(ε, 1−ε)to stay in the valid domain. UsesBeta.PDFas the derivative. Fallback toRootfinding.Brent.tryFindRootWithif 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β=1→InvCDF(p) = p^(1/α)α=1→InvCDF(p) = 1 − (1−p)^(1/β)F.InvCDF
Derived analytically from Beta.InvCDF using the relationship between the F and Beta CDFs:
No new dependencies introduced; all three implementations rely only on the existing
Beta.CDF,Beta.PDF, andRootfinding.Brentalready present in the library.Test Status
22 new regression tests added covering:
p=0,p=1)Beta(2,1),Beta(1,2))InvCDF(p) = −InvCDF(1−p))qt(0.975, 10) = 2.228139,qf(0.95, 3, 4) = 6.5914CDF(InvCDF(p)) ≈ pround-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 NormalMultivariateNormal.InvCDF— complex, not yet addressedStudentizedRange.InvCDF— requires numerical integration, not yet addressed