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

add R^2 statistic for Model #810

Merged
merged 3 commits into from
Oct 23, 2022
Merged

add R^2 statistic for Model #810

merged 3 commits into from
Oct 23, 2022

Conversation

newville
Copy link
Member

Adds R^2 statistic for Model fits, as discussed in #803.

Description

Type of Changes
  • 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?

@codecov
Copy link

codecov bot commented Oct 17, 2022

Codecov Report

Merging #810 (d7ed6d6) into master (fe06ab8) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master     #810   +/-   ##
=======================================
  Coverage   93.87%   93.88%           
=======================================
  Files          10        9    -1     
  Lines        3480     3481    +1     
=======================================
+ Hits         3267     3268    +1     
  Misses        213      213           
Impacted Files Coverage Δ
lmfit/model.py 91.25% <100.00%> (+0.05%) ⬆️
lmfit/printfuncs.py 99.59% <100.00%> (+<0.01%) ⬆️
lmfit/__init__.py

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Contributor

@reneeotten reneeotten left a comment

Choose a reason for hiding this comment

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

also thanks for this @newville - two minor comments

lmfit/model.py Outdated
if self.data is not None and len(self.data) > 1:
sstot = max(tiny, ((self.data - self.data.mean())**2).sum())
if isinstance(self.residual, np.ndarray) and len(self.residual) > 1:
self.rsquared = 1.0 - (self.residual**2).sum() / sstot
Copy link
Contributor

Choose a reason for hiding this comment

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

for readability I would prefer the max(tiny, .....) to be in the line above instead of the sstot define, but that might be a personal preference

Copy link
Member Author

Choose a reason for hiding this comment

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

@reneeotten Yeah, I agree. I think I was fighting line length considerations, but readability is not only line length ;)

@@ -137,6 +137,8 @@ def fit_report(inpars, modelpars=None, show_correl=True, min_correl=0.1,
add(f" reduced chi-square = {getfloat_attr(result, 'redchi')}")
add(f" Akaike info crit = {getfloat_attr(result, 'aic')}")
add(f" Bayesian info crit = {getfloat_attr(result, 'bic')}")
if hasattr(result, 'rsquared'):
add(f" R-squared = {getfloat_attr(result, 'rsquared')}")
Copy link
Contributor

Choose a reason for hiding this comment

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

we should probably also add this to fitreport_html_table?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, thanks, I forgot. Will add.

Copy link
Contributor

@reneeotten reneeotten left a comment

Choose a reason for hiding this comment

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

@newville looks ready to me for a squash-and-merge

@newville newville merged commit 1d860dd into master Oct 23, 2022
@reneeotten reneeotten deleted the add_r2_statistic branch November 25, 2022 14:26
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.

2 participants