Skip to content

Conversation

@perNyfelt
Copy link
Member

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 ✅
  1. 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()
  1. Test Coverage:
  • 18 tests for QuantileRegression - all passing ✅
  • 9 tests for GgStat.quantile() - 8/9 passing
  • 16 tests for GeomQuantile - comprehensive coverage

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
Copilot AI review requested due to automatic review settings January 11, 2026 09:47
Copy link
Contributor

Copilot AI left a 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

perNyfelt and others added 7 commits January 11, 2026 11:15
  - 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
Copy link
Contributor

Copilot AI left a 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.

  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:
Copy link
Contributor

Copilot AI left a 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.

@perNyfelt perNyfelt merged commit 6de4c3e into main Jan 11, 2026
6 checks passed
@perNyfelt perNyfelt deleted the gg-quantile_regression branch January 11, 2026 12:43
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