Skip to content

[ENH] Scatter Plot: Add ellipse/s#6752

Merged
lanzagar merged 7 commits intobiolab:masterfrom
VesnaT:scatter_ellipse
Apr 12, 2024
Merged

[ENH] Scatter Plot: Add ellipse/s#6752
lanzagar merged 7 commits intobiolab:masterfrom
VesnaT:scatter_ellipse

Conversation

@VesnaT
Copy link
Copy Markdown
Contributor

@VesnaT VesnaT commented Mar 4, 2024

Issue

Implements #6734

Description of changes

Add ellipse (similar to regression line).

Includes
  • Code changes
  • Tests
  • Documentation

@janezd janezd self-assigned this Mar 8, 2024
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 11, 2024

Codecov Report

Merging #6752 (cef04c9) into master (ba951fa) will increase coverage by 0.05%.
Report is 56 commits behind head on master.
The diff coverage is 100.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6752      +/-   ##
==========================================
+ Coverage   88.13%   88.18%   +0.05%     
==========================================
  Files         322      326       +4     
  Lines       70589    70994     +405     
==========================================
+ Hits        62216    62609     +393     
- Misses       8373     8385      +12     

@VesnaT
Copy link
Copy Markdown
Contributor Author

VesnaT commented Mar 25, 2024

Screen.Recording.2024-03-25.at.13.22.56.mov

@thocevar
Copy link
Copy Markdown
Contributor

vals, vects = np.linalg.eig(cov)
...
cx = np.cos(m) * np.sqrt(vals[0] * f)
cy = np.sin(m) * np.sqrt(vals[1] * f)

Previously, the stretch of the ellipse was cov[0, 0] which is the variance along each coordinate axis while the stretch should reflect the variance in the direction of the computed eigenvectors. This results in more appropriate shapes. However, the regression line will not be completely in line with the ellipse, because it's minimizing vertical errors and not perpendicular projections.

@janezd
Copy link
Copy Markdown
Contributor

janezd commented Apr 12, 2024

Lines can also minimize perpendicular distance if you set the plot to treat variables as independent.

@thocevar
Copy link
Copy Markdown
Contributor

By using the option "treat variables as independent" the regression line actually lines up with the ellipse. Do we want to prioritize this?

@janezd
Copy link
Copy Markdown
Contributor

janezd commented Apr 12, 2024

By making it a default? Probably not because users expect a regression line. Yet, scatter plot shows relation between two variables, so perpendicular projection should be the default. We never found a good solution to make users aware that there are two possibilities and that they must decide what they want.

Copy link
Copy Markdown
Contributor

@lanzagar lanzagar left a comment

Choose a reason for hiding this comment

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

After the fix everything looks ok.
As discussed we should maybe move this to the base class.

Comment on lines +304 to +305
# https://stats.stackexchange.com/questions/577628/trying-to-understand-how-to-calculate-a-hotellings-t2-confidence-ellipse
# https://stackoverflow.com/questions/66179256/how-to-check-if-a-point-is-in-an-ellipse-in-python
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe replace with the following reference for HotellingEllipse, from where we took the equation to scale for 95%
https://github.com/ChristianGoueguel/HotellingEllipse/blob/master/R/ellipseCoord.R

Comment on lines +318 to +319
cx = np.cos(m) * np.sqrt(cov[0, 0] * f)
cy = np.sin(m) * np.sqrt(cov[1, 1] * f)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Use @thocevar 's fix.

@lanzagar lanzagar changed the title Scatter Plot: Add ellipse/s [ENH] Scatter Plot: Add ellipse/s Apr 12, 2024
@lanzagar lanzagar merged commit 100d989 into biolab:master Apr 12, 2024
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.

4 participants