Skip to content

Comments

Find degrees of freedom for non_central_f distribution#1368

Open
JacobHass8 wants to merge 2 commits intoboostorg:developfrom
JacobHass8:nc-f-find-v1
Open

Find degrees of freedom for non_central_f distribution#1368
JacobHass8 wants to merge 2 commits intoboostorg:developfrom
JacobHass8:nc-f-find-v1

Conversation

@JacobHass8
Copy link
Contributor

Towards #1305. I've added functions to find parameters df1 and df2 because they are nearly identical.

All the tests are passing, but changing the initial guess for the degrees of freedom that is passed to bracket_and_solve causes most tests to fail. Thus, I'm not super confident in the current implementation. I will add more spot checks for a wider range of df1/df2 to make sure things don't break. Perhaps the initial guess should change based on if the different of p - cdf is positive or negative? For now, I'm going to leave it though.

I also had some difficulty with seeing if the function passed to bracket_and_solve was rising or falling. I ultimately found that the following worked

RealType guess = 1; // Changing this to 20, 200 causes errors! 
std::pair<RealType, RealType> ir = tools::bracket_and_solve_root(
   f, guess, RealType(2), f(guess) < 0 ? true : false, tol, max_iter, pol);

where

f_degrees_of_freedom_finder<RealType, Policy> f(x, v, nc, find_v1, p < q ? p : q, p < q ? false : true);

Essentially, if the difference between cdf-p (or is negative then f is increasing, and if it is positive then f is decreasing. I'm not entirely sure why this works though.

Could all of this rising/falling be avoided by minimizing the squared difference (cdf-p)^2? Maybe this will open up a whole new can of worms though.

@codecov
Copy link

codecov bot commented Feb 21, 2026

Codecov Report

❌ Patch coverage is 96.92308% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.34%. Comparing base (a10f3c8) to head (3eb7561).

Files with missing lines Patch % Lines
include/boost/math/distributions/non_central_f.hpp 96.72% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #1368      +/-   ##
===========================================
- Coverage    95.34%   95.34%   -0.01%     
===========================================
  Files          825      825              
  Lines        68160    68224      +64     
===========================================
+ Hits         64987    65048      +61     
- Misses        3173     3176       +3     
Files with missing lines Coverage Δ
test/test_nc_f.cpp 100.00% <100.00%> (ø)
include/boost/math/distributions/non_central_f.hpp 89.70% <96.72%> (+1.73%) ⬆️

... and 1 file with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a10f3c8...3eb7561. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant