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 <quikee@gmail.com>
Tested-by: Tomaž Vajngerl <quikee@gmail.com>
This commit is contained in:
Laurent Balland-Poirier
2014-03-01 00:20:53 +01:00
committed by Tomaž Vajngerl
parent 6a71b8d902
commit 00cb825ab3

View File

@@ -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
{