[Libreoffice-commits] core.git: Branch 'libreoffice-4-2' - chart2/source
Laurent Balland-Poirier
laurent.balland-poirier at laposte.net
Mon Feb 10 00:05:26 PST 2014
chart2/source/tools/PolynomialRegressionCurveCalculator.cxx | 15 +++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
New commits:
commit bac928cf6405c869ab83bc136dac52b037386108
Author: Laurent Balland-Poirier <laurent.balland-poirier at laposte.net>
Date: Wed Jan 8 22:37:52 2014 +0100
fdo#73374 Trendline: correct R^2 for forced intercept
In case of forced intercept, R^2 must be calculated in a different way.
This patch calculates R^2 of trend line in the same way as LINEST
function.
Change-Id: I3ac361f014569261f05d513acb3428de5c7641ab
Reviewed-on: https://gerrit.libreoffice.org/7326
Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
Tested-by: Tomaž Vajngerl <quikee at gmail.com>
(cherry picked from commit 9e67015be6e9e53e19466117d692de17c18463da)
Reviewed-on: https://gerrit.libreoffice.org/7956
Tested-by: Markus Mohrhard <markus.mohrhard at googlemail.com>
Reviewed-by: Markus Mohrhard <markus.mohrhard at googlemail.com>
diff --git a/chart2/source/tools/PolynomialRegressionCurveCalculator.cxx b/chart2/source/tools/PolynomialRegressionCurveCalculator.cxx
index 951c071..21b564d 100644
--- a/chart2/source/tools/PolynomialRegressionCurveCalculator.cxx
+++ b/chart2/source/tools/PolynomialRegressionCurveCalculator.cxx
@@ -167,6 +167,8 @@ void SAL_CALL PolynomialRegressionCurveCalculator::recalculateRegression(
// Calculate correlation coeffitient
double aSumError = 0.0;
double aSumTotal = 0.0;
+ double aSumYpred2 = 0.0;
+ double aSumYactual2 = 0.0;
for( sal_Int32 i = 0; i < aNoValues; i++ )
{
@@ -175,9 +177,20 @@ void SAL_CALL PolynomialRegressionCurveCalculator::recalculateRegression(
double yPredicted = getCurveValue( xValue );
aSumTotal += (yActual - yAverage) * (yActual - yAverage);
aSumError += (yActual - yPredicted) * (yActual - yPredicted);
+ aSumYpred2 += yPredicted * yPredicted;
+ aSumYactual2 += yActual * yActual;
}
- double aRSquared = 1.0 - (aSumError / aSumTotal);
+ double aRSquared = 0.0;
+ if(mForceIntercept)
+ {
+ if(aSumYactual2 != 0.0)
+ aRSquared = aSumYpred2 / aSumYactual2;
+ }
+ else
+ {
+ aRSquared = 1.0 - (aSumError / aSumTotal);
+ }
if (aRSquared > 0.0)
m_fCorrelationCoeffitient = std::sqrt(aRSquared);
More information about the Libreoffice-commits
mailing list