-
Notifications
You must be signed in to change notification settings - Fork 2
Quantile Regression #83
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
Conversation
Core Implementation 1. QuantileRegression Class (matrix-stats): - Implemented using the Barrodale-Roberts simplex algorithm - Supports any quantile τ in (0, 1) - Full API matching LinearRegression: constructors, predict methods, accessors - All 18 unit tests passing ✅ 2. Integration Components (matrix-charts): - Added StatType.QUANTILE enum value - Created StatsQuantile wrapper class - Implemented GgStat.quantile() method for statistical transformation - Integrated with GgRenderer.applyStats() - Created GeomQuantile class for rendering - Added factory methods: geom_quantile() and stat_quantile() 3. Test Coverage: - 18 tests for QuantileRegression - all passing ✅ - 9 tests for GgStat.quantile() - 8/9 passing - 16 tests for GeomQuantile - comprehensive coverage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR implements quantile regression functionality, enabling estimation of conditional quantiles (rather than conditional means) through linear regression lines. The implementation adds a QuantileRegression class using linear programming via Apache Commons Math's SimplexSolver, along with full integration into the matrix-charts plotting framework.
Changes:
- Implemented QuantileRegression class with linear programming formulation for any quantile τ in (0, 1)
- Added geom_quantile() and stat_quantile() factory methods with full API support for custom quantiles, styling, and rendering options
- Created comprehensive test suites with 43 total tests covering core algorithms, statistical transformations, and rendering
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 11 comments.
Show a summary per file
| File | Description |
|---|---|
| matrix-stats/.../QuantileRegression.groovy | Core quantile regression implementation using simplex algorithm with tau validation and prediction methods |
| matrix-stats/.../QuantileRegressionTest.groovy | 18 comprehensive unit tests covering basic regression, edge cases, predictions, and error handling |
| matrix-charts/.../StatsQuantile.groovy | Wrapper class for stat_quantile configuration |
| matrix-charts/.../GgStat.groovy | Statistical transformation method implementing quantile regression line generation |
| matrix-charts/.../GeomQuantile.groovy | Geometry class for rendering quantile regression lines with SVG |
| matrix-charts/.../GgRenderer.groovy | Integration of QUANTILE stat type into rendering pipeline |
| matrix-charts/.../Layer.groovy | Addition of QUANTILE enum value to StatType |
| matrix-charts/.../GgPlot.groovy | Factory methods geom_quantile() and stat_quantile() with documentation |
| matrix-charts/.../GgStatTest.groovy | 9 tests for GgStat.quantile() covering parameters, grouping, and error cases |
| matrix-charts/.../GeomQuantileTest.groovy | 16 tests for GeomQuantile covering rendering, styling, and edge cases |
| matrix-charts/ggTodo.md | Marked geom_quantile and stat_quantile as completed |
matrix-stats/src/main/groovy/se/alipsa/matrix/stats/regression/QuantileRegression.groovy
Outdated
Show resolved
Hide resolved
matrix-stats/src/main/groovy/se/alipsa/matrix/stats/regression/QuantileRegression.groovy
Show resolved
Hide resolved
matrix-stats/src/main/groovy/se/alipsa/matrix/stats/regression/QuantileRegression.groovy
Outdated
Show resolved
Hide resolved
matrix-charts/src/main/groovy/se/alipsa/matrix/gg/geom/GeomQuantile.groovy
Outdated
Show resolved
Hide resolved
matrix-charts/src/main/groovy/se/alipsa/matrix/gg/geom/GeomQuantile.groovy
Show resolved
Hide resolved
matrix-stats/src/main/groovy/se/alipsa/matrix/stats/regression/QuantileRegression.groovy
Outdated
Show resolved
Hide resolved
matrix-charts/src/main/groovy/se/alipsa/matrix/gg/stat/GgStat.groovy
Outdated
Show resolved
Hide resolved
…/QuantileRegression.groovy Co-authored-by: Copilot <[email protected]>
…/QuantileRegression.groovy Co-authored-by: Copilot <[email protected]>
…/QuantileRegression.groovy Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
- Added validation to check if required columns (x, y, group) exist before accessing them - Added null checks for individual row values to prevent NullPointerException - If columns are missing, the render method returns early instead of failing 2. Removed dead code in QuantileRegression.groovy (lines 126-152) - Removed the unused first formulation that was never executed - Kept only the reformulated version that's actually used by the solver - Improved code maintainability and clarity 3. Optimized list filtering in GgStat.groovy (lines 706-721) - Added clear documentation explaining why filtering is needed - Changed List<Number> to List<?> for better type handling - Added explicit casts to make the filtering logic clearer 4. Fixed division by zero risk in GgStat.groovy (line 732) - Critical fix: Changed Elvis operator ?: to explicit null check - The Elvis operator was treating 0 as falsy, defaulting to 80 instead of using the provided 0 value - Added validation to ensure nPoints >= 2 with clear error message 5. Added 'quantiles' to STAT_PARAM_KEYS in GgChart.groovy (line 70) - Added 'quantiles' to the list of stat parameters - This ensures the quantiles parameter flows correctly from geom_quantile() to GgStat.quantile() 6. Added test coverage for invalid 'n' parameter (GgStatTest.groovy lines 1318-1344) - Added comprehensive test for n = 0, n = 1, and n < 0 - All test cases verify the error message contains "must be at least 2" Bonus Fixes - Fixed testQuantileEmptyData test: Discovered that Matrix.builder().rows([]) doesn't preserve column names. Removed the .rows([]) call to let the Matrix constructor create empty columns from the header list. - All quantile-related tests in GgStatTest are now passing (previously 8/10 were passing) - All matrix-stats tests continue to pass
…quantile_regression # Conflicts: # matrix-stats/src/main/groovy/se/alipsa/matrix/stats/regression/QuantileRegression.groovy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
matrix-charts/src/main/groovy/se/alipsa/matrix/gg/geom/GeomQuantile.groovy
Outdated
Show resolved
Hide resolved
matrix-stats/src/main/groovy/se/alipsa/matrix/stats/regression/QuantileRegression.groovy
Show resolved
Hide resolved
Changed from: Map-based lookup that implicitly returns null for unknown types Changed to: Switch statement with explicit case for 'solid' (matching GeomUtils pattern) Issue 2: Consistent tau documentation in QuantileRegression.groovy Changed: Clarified that τ is the mathematical symbol for the parameter named 'tau' in code Before: * For a given quantile τ (tau), the regression line minimizes the asymmetric loss function: After: * For a given quantile tau (denoted mathematically as τ), the regression line minimizes * the asymmetric loss function:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated no new comments.
Core Implementation