Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update confidence.rst #942

Merged
merged 8 commits into from
Mar 2, 2024
Merged

Update confidence.rst #942

merged 8 commits into from
Mar 2, 2024

Conversation

skoldobskiy
Copy link
Contributor

@skoldobskiy skoldobskiy commented Feb 26, 2024

Hello!
I found a bug in an example with calculating c.i.
The assessment of sigma's and related plotting of confidence intervals performed with sqrt(chi2/redchi), however, it should be sqrt((chi2-chi2.min)/redchi). The updated equation provides accurate and adequate contour plots for parameter uncertainties.

Also renaming dchi2 to chi2 can be considered.

Description

https://lmfit.github.io/lmfit-py/confidence.html#lmfit.conf_interval2d -- no ellipses are plotted here, however, they should. The proposed change corrects this.

no no
Type of Changes
  • [ x] Bug fix
  • New feature
  • Refactoring / maintenance
  • Documentation / examples
Tested on
Verification

Have you

  • included docstrings that follow PEP 257?
  • referenced existing Issue and/or provided relevant link to mailing list?
  • verified that existing tests pass locally?
  • verified that the documentation builds locally?
  • squashed/minimized your commits and written descriptive commit messages?
  • added or updated existing tests to cover the changes?
  • updated the documentation and/or added an entry to the release notes (doc/whatsnew.rst)?
  • added an example?

Hello!
I found a bug in an example with calculating c.i.
The assessment of sigma's and related plotting of confidence intervals performed with sqrt(chi2/redchi), however, it should be sqrt((chi2-chi2.min)/redchi).
The updated equation provides accurate and adequate contour plots for parameter uncertainties.
@newville
Copy link
Member

@skoldobskiy Ah, good catch. We do that subtraction with conf_interval2d(....., chi2_out=False) but not with
conf_interval2d(....., chi2_out=True). I guess it is easier to change the doc than the code, especially because chi2.min() is sometimes an interesting thing to know.

So, I'm +1 on this change. I'll leave this open for a couple of days in case there are any objections or other considerations. But, I hope to merge this and #941 and then be ready to push a release soonish.

@skoldobskiy
Copy link
Contributor Author

skoldobskiy commented Feb 26, 2024

@newville Also I propose that the doc [https://lmfit.github.io/lmfit-py/confidence.html#lmfit.conf_interval2d] can be changed in a way to emphasize that conf_interval2d studies the ellipses of standard errors, not those obtained by conf_interval(out, out, sigmas=sigma_levels) (if I understood the procedures correctly).
Currently, this is not clear to the reader/user and very similar naming can be a reason of misinterpretation.

@newville
Copy link
Member

@skoldobskiy If you have wording there that you want to change, are you willing to include that in this PR? I would say "please do!"

@skoldobskiy
Copy link
Contributor Author

  1. I found that https://lmfit.github.io/lmfit-py/examples/documentation/confidence_chi2_maps.html#sphx-glr-examples-documentation-confidence-chi2-maps-py is corrected already. I updated my old version with this example to synchronize them.
  2. I also have added a couple of sentences in the confidence interval discussion -- for clarification. However I would like if somebody can check that I am fully correct

@newville
Copy link
Member

@skoldobskiy it looks like there are some RST formatting issues - like single quotes where you might want double backticks. Have you installed and run "pre-commit"? That might help identify those issues.

# you could calculate the matrix of probabilities from sigma as:
# prob_mat = np.erf(sigma_mat/np.sqrt(2))
if explicitly_calculate_sigma:
print("Generating chi-square map for ", pairs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use a formatting string

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@newville @reneeotten Ok thanks, I'll check and fix it.

@newville
Copy link
Member

@skoldobskiy Thanks -- this looks okay to me. @reneeotten any objection from anyone to Squash+Merge? If I don't hear otherwise, I will plan to do that on Monday.

@reneeotten reneeotten merged commit 6658cc6 into lmfit:master Mar 2, 2024
14 checks passed
@newville
Copy link
Member

newville commented Mar 2, 2024

@skoldobskiy @reneeotten Thanks!

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.

3 participants