MCPcopy Create free account
hub / github.com/antlr/codebuff / leastSquaresFit

Method leastSquaresFit

output/java_guava/1.4.17/PairedStats.java:200–216  ·  view source on GitHub ↗

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

()

Source from the content-addressed store, hash-verified

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}

Callers

nothing calls this directly

Calls 9

countMethod · 0.95
forNaNMethod · 0.95
mappingMethod · 0.95
horizontalMethod · 0.95
verticalMethod · 0.95
checkStateMethod · 0.45
sumOfSquaresOfDeltasMethod · 0.45
withSlopeMethod · 0.45
meanMethod · 0.45

Tested by

no test coverage detected