Returns a linear transformation giving the best fit to the data according to Ordinary Least Squares linear regression of y as a function of x. The count must be greater than one, and either the x or y
()
| 198 | |
| 199 | |
| 200 | public LinearTransformation leastSquaresFit() { |
| 201 | checkState(count() > 1); |
| 202 | if (isNaN(sumOfProductsOfDeltas)) { |
| 203 | return LinearTransformation.forNaN(); |
| 204 | } |
| 205 | double xSumOfSquaresOfDeltas = xStats.sumOfSquaresOfDeltas(); |
| 206 | if (xSumOfSquaresOfDeltas > 0.0) { |
| 207 | if (yStats.sumOfSquaresOfDeltas() > 0.0) { |
| 208 | return LinearTransformation.mapping(xStats.mean(), yStats.mean()).withSlope(sumOfProductsOfDeltas / xSumOfSquaresOfDeltas); |
| 209 | } else { |
| 210 | return LinearTransformation.horizontal(yStats.mean()); |
| 211 | } |
| 212 | } else { |
| 213 | checkState(yStats.sumOfSquaresOfDeltas() > 0.0); |
| 214 | return LinearTransformation.vertical(xStats.mean()); |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | /** |
| 219 | * {@inheritDoc} |
nothing calls this directly
no test coverage detected