Bug 105427 - : trendline formula wrong for second degree polynomial approximation
Summary: : trendline formula wrong for second degree polynomial approximation
Status: RESOLVED NOTABUG
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
5.1.6.2 release
Hardware: x86-64 (AMD64) Linux (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-01-18 19:05 UTC by andi
Modified: 2017-01-21 12:18 UTC (History)
3 users (show)

See Also:
Crash report or crash signature:


Attachments
graphics of the description above (14.63 KB, application/pdf)
2017-01-18 19:05 UTC, andi
Details

Note You need to log in before you can comment on or make changes to this bug.
Description andi 2017-01-18 19:05:50 UTC
Created attachment 130537 [details]
graphics of the description above

given: 3 points x1/y1; x2/y2; x3/y3

generate: a graph through theses 3 points

apply: trendline to approximate this graph; for approximation
use second degree polynom for approximation

show: formula of the trendline

formula is wrong for approximation trendline with second degree polynom approximation (hint: e.g. third degree does not show the mistake)

example: 
(A1/B1) = (-2/4)
(A2/B2) = (0/0)
(A3/B3) = (2/4)

graph through these three points is a normal parabola y(x)=x²

trendline looks o.k. but it shows the formula y(x)=4*x²-16*x+16 (wrong!)

y(0)=4*0²-16*0+16 (wrong)
Comment 1 Xisco Faulí 2017-01-18 19:43:40 UTC Comment hidden (obsolete)
Comment 2 andi 2017-01-18 21:42:53 UTC
problem description in brief: 

error in approximation formula 
formula is derived from trendline 
trendline looks o.k.
error applies to approximation with second degree polynom
Comment 3 andi 2017-01-19 07:42:26 UTC
one of the later Libre Office calc versions (5.1.6.2) shows the same bug
Comment 4 GerardF 2017-01-19 20:40:05 UTC
Are you using a *line chart* ?
See the LibreOffice Help :

https://help.libreoffice.org/Chart/Trend_Lines
"If you insert a trend line to a chart type that uses categories, like Line or Column, then the numbers 1, 2, 3, … are used as x-values to calculate the trend line. For such charts the XY chart type might be more suitable."

You must use X/Y chart for this purpose.
Comment 5 andi 2017-01-20 06:26:11 UTC
sorry sirs, the question is not "more suitable"

- no matter if chosen "curve" or "line" chart the resulting formula is wrong!

- mathematical background: to approximate 3 given x/y points the resulting formula with second square polynom finds all these given points exactly!!!

- the correct resulting formula for the 3 points (-2/4) (0/0) (2/4) would be y(x)=x²

- the wrong trendline formula found by calc is: y(x) = 4x²-16x+16
- try with (0/0); does y(x)=4x²-16x+16 hit (0/0)? No!
- does y(x)=x² hit (0/0) Yes!

This bug is serious and I would appreciate if you try see the math behind it and check then what you get from cal 

Thanks lot!
Comment 6 GerardF 2017-01-20 08:55:54 UTC
(In reply to andi from comment #5)
 
> - no matter if chosen "curve" or "line" chart the resulting formula is wrong!
> 
> - mathematical background: to approximate 3 given x/y points the resulting
> formula with second square polynom finds all these given points exactly!!!
> 
> - the correct resulting formula for the 3 points (-2/4) (0/0) (2/4) would be
> y(x)=x²
> 
> - the wrong trendline formula found by calc is: y(x) = 4x²-16x+16
> - try with (0/0); does y(x)=4x²-16x+16 hit (0/0)? No!
> - does y(x)=x² hit (0/0) Yes!

As said in the help, with a line chart, trendline equation use 1, 2, 3... as X points.
So your 3 points are not (-2/4) (0/0) (2/4) but (1/4) (2/0) (3/4) and (2/0) gives 4*2^2-16*2+16 = 0

If there is a bug here, he is in the help. (not enough explicit)
Comment 7 andi 2017-01-20 20:50:53 UTC
o.k., I got the concept now and had a wrong understanding of how the trandline is calculated. It is not calculated with the given points (x1/y1) ...(xn/yn) but with (1/y1) ..(n/yn)

Thanks for this clarification! 

I set the status to "resolved". Thanks again!
Comment 8 steve 2017-01-21 12:18:21 UTC
Since there is no specific commit fixing this issue, setting to WORKSFORME. Or if I understood the discussion correctly it's actually working as expected so NOTABUG is correct here.

Feel free to update if you disagree.