chart2/source/tools/PolynomialRegressionCurveCalculator.cxx |    8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

New commits:
commit 00cb825ab3f16a94f1e8311ba0c24f72588e788e
Author: Laurent Balland-Poirier <laurent.balland-poir...@laposte.net>
Date:   Sat Mar 1 00:20:53 2014 +0100

    fdo#75538 R^2 calculation for trendline similar to LINEST function
    
    Modify for forced intercept of trendline, calculation of R^2 in the same
    way as LINEST function does calculation
    
    Change-Id: Ic943b1ca1bbe30b1a4b88e2a338eb9dc34d848b6
    Reviewed-on: https://gerrit.libreoffice.org/8402
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>
    Tested-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/chart2/source/tools/PolynomialRegressionCurveCalculator.cxx 
b/chart2/source/tools/PolynomialRegressionCurveCalculator.cxx
index 90be5a1..9b39e01 100644
--- a/chart2/source/tools/PolynomialRegressionCurveCalculator.cxx
+++ b/chart2/source/tools/PolynomialRegressionCurveCalculator.cxx
@@ -168,7 +168,6 @@ void SAL_CALL 
PolynomialRegressionCurveCalculator::recalculateRegression(
     double aSumError = 0.0;
     double aSumTotal = 0.0;
     double aSumYpred2 = 0.0;
-    double aSumYactual2 = 0.0;
 
     for( sal_Int32 i = 0; i < aNoValues; i++ )
     {
@@ -177,15 +176,14 @@ 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;
+        if(mForceIntercept)
+            aSumYpred2 += (yPredicted - mInterceptValue) * (yPredicted - 
mInterceptValue);
     }
 
     double aRSquared = 0.0;
     if(mForceIntercept)
     {
-        if(aSumYactual2 != 0.0)
-            aRSquared = aSumYpred2 / aSumYactual2;
+        aRSquared = aSumYpred2 / (aSumError + aSumYpred2);
     }
     else
     {
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to