diff options
author | Laurent Balland-Poirier <laurent.balland-poirier@laposte.net> | 2014-01-08 22:37:52 +0100 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2014-02-07 12:01:10 +0000 |
commit | 9e67015be6e9e53e19466117d692de17c18463da (patch) | |
tree | d4a8640da46c01c747580d52e6809f91c1c3f6cb /chart2/source/tools | |
parent | 436c0fc9f6ba9b9a7af2ec37554243f82449f4ef (diff) |
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@gmail.com>
Tested-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'chart2/source/tools')
-rw-r--r-- | chart2/source/tools/PolynomialRegressionCurveCalculator.cxx | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/chart2/source/tools/PolynomialRegressionCurveCalculator.cxx b/chart2/source/tools/PolynomialRegressionCurveCalculator.cxx index 951c071a2ca0..21b564d63d08 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); |