Kaydet (Commit) 9e67015b authored tarafından Laurent Balland-Poirier's avatar Laurent Balland-Poirier Kaydeden (comit) Tomaž Vajngerl

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/7326Reviewed-by: 's avatarTomaž Vajngerl <quikee@gmail.com>
Tested-by: 's avatarTomaž Vajngerl <quikee@gmail.com>
üst 436c0fc9
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment