[Solved] Trend line calculation in chart

Discuss the spreadsheet application
Locked
epb
Posts: 4
Joined: Tue Jun 22, 2010 6:59 pm

[Solved] Trend line calculation in chart

Post by epb »

Hi,

How does OpenOffice calculate the trend lines that can be inserted in graphs? According to Wikipedia there are several methods to do linear regression, and I would like to know which one OO uses... http://en.wikipedia.org/wiki/Linear_regression

Any help appreciated!
Last edited by MrProgrammer on Thu Sep 05, 2024 3:53 am, edited 2 times in total.
Reason: Edited topic's subject
OpenOffice 3.2 on MacOS 10.6
User avatar
Robert Tucker
Volunteer
Posts: 1250
Joined: Mon Oct 08, 2007 1:34 am
Location: Manchester UK

Re: Trend line

Post by Robert Tucker »

This page:

http://dataninja.wordpress.com/2006/02/ ... lications/

would lead me to believe that it is an ordinary least squares (OLS) fit – or was in 2006!
LibreOffice 7.x.x on Arch and Fedora.
User avatar
Zizi64
Volunteer
Posts: 11509
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Trend line

Post by Zizi64 »

Self made solution:
For linear regression use the 'LINEST' function, for logarithmic regression use the 'LOGEST' function. See in OOo Help. Attention: the LINEST and LOGEST functions are ARRAY FUNCTIONS! See in OOo Help too!
If 'y' datas of chart scattered along a theoretical straight line, then the linear regression will be really "LINEAR" estimation:
y = a*x^1+b*x^0 or the known format y = a*x+b: this is the equotion of straigth line.
The LINEST function able to determine the 'a' and 'b' constant values of equotion.

The format of more-degree of polynomial expession:
The linear regression maybe write to polinomial format with 'n' exponent: y = c0*x^0 + c1*x^1 + c2*x^2 +... cn*x^n

see the example file:
Linear regression.ods
(24.7 KiB) Downloaded 511 times

Another solution:
In chart edit: Click on serial (on line) Insert->trendline...
Linear regression.png
Linear regression.png (11.9 KiB) Viewed 10002 times
Tibor Kovacs, Hungary; LO7.5.8/25.8.5.2 /Win7-10-11 x64Prof.
PortableApps: LO3.3.0-25.8.5.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
MrProgrammer
Moderator
Posts: 5455
Joined: Fri Jun 04, 2010 7:57 pm
Location: Wisconsin, USA

Re: Trend line

Post by MrProgrammer »

I inserted a linear trendline on a graph and had it's equation displayed. (R squared was .9916 so the relationship was close to linear but not exact.) Then I used LINEST to calculate the slope and intercept of the least squares line. The trendline equation matches the LINEST calculation to 9 significant digits. Help says "LINEST finds a straight line y = a + bx that best fits the data, using linear regression (the least squares method)" therefore the graph's trendline is calculated the same way.
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.7.8, iMac Intel.   The locale for any menus or Calc formulas in my posts is English (USA).
epb
Posts: 4
Joined: Tue Jun 22, 2010 6:59 pm

Re: Trend line

Post by epb »

MrProgrammer wrote:I inserted a linear trendline on a graph and had it's equation displayed. (R squared was .9916 so the relationship was close to linear but not exact.) Then I used LINEST to calculate the slope and intercept of the least squares line. The trendline equation matches the LINEST calculation to 9 significant digits. Help says "LINEST finds a straight line y = a + bx that best fits the data, using linear regression (the least squares method)" therefore the graph's trendline is calculated the same way.
Great, that must be the answer then! :)
OpenOffice 3.2 on MacOS 10.6
User avatar
MrProgrammer
Moderator
Posts: 5455
Joined: Fri Jun 04, 2010 7:57 pm
Location: Wisconsin, USA

Re: [Solved] Trend line

Post by MrProgrammer »

If we aren't sure how LINEST does its calculations we can use the actual least squares formulas for Slope
Slope.png
Slope.png (8.79 KiB) Viewed 9964 times
and Intercept
Intercept.png
Intercept.png (9.09 KiB) Viewed 9964 times
In Calc terms the slope is COVAR(x;y)/VARP(x) and the intercept is AVERAGE(y)-Slope*AVERAGE(x). These results are the same as the values from LINEST, proving that it uses the least squares method.
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.7.8, iMac Intel.   The locale for any menus or Calc formulas in my posts is English (USA).
Locked