Board index » cppbuilder » LINEST

LINEST


2007-03-15 04:18:52 AM
cppbuilder113
Hi guys,
Probably not a NativeAPI function question, but anyway; I am being
tasked to reproduce some of the power that is in the Excel LINEST
function in an application.
I realize that LINEST uses linear regression and least squares; but I am
by no means a math major, the Numerical Recipes in C book has been
mildly helpful; but I am still stuck without a solution.
I can't use OLE to automate Excel as the application may not always be
ran on a PC with Excel.
Anyone know any great libraries I could use that allow me to import a
data set of X and Y values which will return me the best polynomial fit
line, or array of A values for the equation y = A1x^2 + A2x + A3?
Dan
 
 

Re:LINEST

Dan wrote:
Quote
Anyone know any great libraries I could use that allow me to import a
Probably Gnumeric
www.gnome.org/projects/gnumeric/
Or OpenOffice.
 

Re:LINEST

Quote
www.gnome.org/projects/gnumeric/
Interesting tool, but gnumeric doesn't have a polynomial fit, which is
the part of LINEST I am interested in; the simple line fit (y=mx+b) is
easy to duplicate, but I am trying to solve for a1..an in the formula
(y=a1x^3 + a2x^2 + a3x + a4); LINEST in Excel gives me that also.
Any other ideas?
 

{smallsort}

Re:LINEST

Dan wrote:
Quote
I realize that LINEST uses linear regression and least squares; but I am
by no means a math major, the Numerical Recipes in C book has been
mildly helpful; but I am still stuck without a solution.
Are you looking at chapter 15?
What part are you having problems with?
Quote
line, or array of A values for the equation y = A1x^2 + A2x + A3?
15.1.5 Chi-Square:
Chi-squared = sum i = 1 to n of
square of
( ( y[i] - quadratic( x[i], a1, a2, a3 ) ) / sigma )
Or, the sum of the squares of the differences between actual and
function values (divided by expected measurement error deviation)
Your job would then be to pick the A's that minimize the Chi-square.
If x is a timeline, then you could normalize it to 0 so x[0] == 0 and
a3 == y[0]
 

Re:LINEST

"Dan" < XXXX@XXXXX.COM >wrote in message
Quote
Probably not a NativeAPI function question, but anyway; I am being tasked to
reproduce some of the power that is in the Excel LINEST function in an
application.
www.nag.co.uk/numeric/fl/manual/html/E02/e02_conts.html
The PDF docs that are linked usually contain enough maths to reproduce the
function in code. It certainly worked for my skew and kurtosis stats analyses.
HTH,
--
Mark Jacobs
DK Computing
www.dkcomputing.co.uk
 

Re:LINEST

Thanks to all; I struggled with NR that I finally just went brute force
and wrote some code from scratch using the formulas on-line for partial
least squares from wolfram.
But since folks are out there and are using numerical recipes.. in
Chapter 15 they go on to further state that if the values Y were from
multiple variables (such as a,b, and c) vs. just X, that simple change
of the code could take place to get the correct formulas for a,b, and c.
Has anyone done something like that, any place I could look for
additional information?