Bug 117318 - Wrong SIGMA SLOPE value calculated with LINEST function
Summary: Wrong SIGMA SLOPE value calculated with LINEST function
Status: RESOLVED INVALID
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
6.0.3.2 release
Hardware: x86-64 (AMD64) Linux (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-04-28 13:34 UTC by Pablo Wagner
Modified: 2018-04-29 00:00 UTC (History)
3 users (show)

See Also:
Crash report or crash signature:


Attachments
Sample data (27.35 KB, application/vnd.oasis.opendocument.spreadsheet)
2018-04-28 13:34 UTC, Pablo Wagner
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Pablo Wagner 2018-04-28 13:34:26 UTC
Created attachment 141741 [details]
Sample data

I'm trying to obtain the uncertainty in the determination of the slope in a linear regression analysis of some data. This sigma slope value is calculated in LibreOffice as if the line intersects the (0,0) value (b=0 in y=mx+b), regardless of what the "b" value is. 

Here's where this value is actually calculated:
https://opengrok.libreoffice.org/xref/core/sc/source/core/tool/interpr5.cxx#2464

I'm attaching a ODS spreadsheet as an example.
Comment 1 raal 2018-04-28 14:26:16 UTC
Hello, please could you specify which formulas are wrong a what are expected values? I compared values from range B35:C39 (only here I see function linest) with excel and the values are the same. Thank you
Comment 2 Pablo Wagner 2018-04-28 14:43:20 UTC
(In reply to raal from comment #1)
> Hello, please could you specify which formulas are wrong a what are expected
> values? I compared values from range B35:C39 (only here I see function
> linest) with excel and the values are the same. Thank you

I've already tried in Excel and it's also wrong. 

The expected value for the variance of sigma_slope should be (J52)^2, not B36^2. M52^2 is the variance of sigma_slope calculated step by step, assuming the intercept with the Y-axis is zero. As can be seen, the LINEST function is returning the statistic sigma_slope as if the intercept with the Y-axis is zero, which, in this case, isn't zero (close, but not zero).

The link in the OP points to the source code where that value is calculated, and apparently it's wrong.
Comment 3 Pablo Wagner 2018-04-28 15:01:13 UTC
(In reply to Pablo Wagner from comment #2)
> (In reply to raal from comment #1)
> > Hello, please could you specify which formulas are wrong a what are expected
> > values? I compared values from range B35:C39 (only here I see function
> > linest) with excel and the values are the same. Thank you
> 
> I've already tried in Excel and it's also wrong. 
> 
> The expected value for the variance of sigma_slope should be (J52)^2, not
> B36^2. M52^2 is the variance of sigma_slope calculated step by step,
> assuming the intercept with the Y-axis is zero. As can be seen, the LINEST
> function is returning the statistic sigma_slope as if the intercept with the
> Y-axis is zero, which, in this case, isn't zero (close, but not zero).
> 
> The link in the OP points to the source code where that value is calculated,
> and apparently it's wrong.


The expected value for the variance of the slope should be (J52)^2, not B36^2. M52^2 is the variance of the slope calculated step by step, assuming the intercept with the Y-axis is zero. As can be seen, the LINEST function is returning the statistic sigma_slope as if the intercept with the Y-axis is zero, which, in this case, isn't zero (close, but not zero).

EDITED: Wrong quantity (variance sigma_slope isn't right)
Comment 4 raal 2018-04-28 15:40:16 UTC
Winfried, maybe you're interested.
Comment 5 Regina Henschel 2018-04-28 16:02:30 UTC
Find the definition of the function LINEST at http://docs.oasis-open.org/office/v1.2/os/OpenDocument-v1.2-os-part2.html#LINEST.
Comment 6 Pablo Wagner 2018-04-28 17:36:56 UTC
(In reply to Regina Henschel from comment #5)
> Find the definition of the function LINEST at
> http://docs.oasis-open.org/office/v1.2/os/OpenDocument-v1.2-os-part2.
> html#LINEST.

Everything seems OK there. But still, fSigmaSlope = fRMSE / sqrt(fSumX2) is wrong, since it's not giving the right value. 

According to the specs in the link provided, sigma_slope should be S_m as in:
http://pages.mtu.edu/~fmorriso/cm3215/UncertaintySlopeInterceptOfLeastSquaresFit.pdf page 5 (quick Google search).
Comment 7 Pablo Wagner 2018-04-29 00:00:08 UTC
OK, I'm really ashamed. I forgot to fix the cell with the intercept parameter where I calculated the residuals. So, it was being set equal to zero for everything but the first term. 

I'm closing this bug report as INVALID.
Sorry for wasting your time. Thanks.