Skip to content

feat: add reduced statistics and dof to report#240

Open
jamesrafe wants to merge 1 commit intoJuliaAstro:mainfrom
jamesrafe:feat/reporting-fit-statistics
Open

feat: add reduced statistics and dof to report#240
jamesrafe wants to merge 1 commit intoJuliaAstro:mainfrom
jamesrafe:feat/reporting-fit-statistics

Conversation

@jamesrafe
Copy link
Copy Markdown
Contributor

@jamesrafe jamesrafe commented Mar 21, 2026

What's Changed

Closes #84 . This PR adds reduced statistics ($\chi_\nu^2$) and d.o.f. (degrees of freedom) for the fit results reporting. The reduced statistics and dof will be shown in the fit results report for individual model slices and the total fit, as well as the plot recipe.

The dof function for individual model slices returns ( number of usable data bins ) − ( number of free parameters ). We get the usable data bins count from data_cache[i].objective. In _objective_to_unit, they already applied the data mask, meaning it has excluded bad channels.

We get the free parameters count from free_mask[parameter_bindings[i]]. parameter_bindings[i] returns the indices of the current dataset's parameters. With those indices, we index the global free mask (which contains all parameters, and is 1/true if free, and 0/false if not) with the parameter bindings of that dataset to get an array of free parameters belonging to the current dataset. Then, we just need to count the number of 1 (True) values.

The reduced_statistic function then just takes the statistic of a slice (which we already have) and divide it by the dof of said slice. If dof is zero, it will return Inf or NaN, as per Julia's response.

We do not use the dof function for the total degrees of freedom because of parameter binding. If multiple datasets share a tied parameter, summing up each slice's dof will double-count the tied parameters. Instead, we just use count(free_mask) to get the total free parameters. The number of usable bins can just be summed up though, so we just need to reduce the summed-up objectives by count(free_mask).

Please help in reviewing this, to make sure the math and usage of the variables are correct, and if the format for showing the statistics is good. Thank you very much!

Screenshots

First report and the plot comes from s54405.pha, while second report uses hisum.pha and losum.pha.

Before

image image image

After

image image image

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 21, 2026

Codecov Report

❌ Patch coverage is 78.94737% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 56.56%. Comparing base (62aba68) to head (cbd050f).

Files with missing lines Patch % Lines
src/plots-recipes.jl 0.00% 2 Missing ⚠️
src/statistics.jl 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #240      +/-   ##
==========================================
+ Coverage   55.69%   56.56%   +0.86%     
==========================================
  Files          39       39              
  Lines        2632     2650      +18     
==========================================
+ Hits         1466     1499      +33     
+ Misses       1166     1151      -15     

☔ View full report in Codecov by Sentry.
📢 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.

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.

Reporting fit statistics

1 participant