|
From: Hans-Bernhard B. <br...@ph...> - 2005-05-11 13:03:22
|
Maurice Al-Khaliedy wrote:
> i have a problem with gnuplot 4.0 and Linear Regression.
gnuplot doesn't do linear regression. It does non-linear least-squares
fitting, which encloses linear fits to a simple straight line as a
special case.
> I got different values between MS excel and gnuplot.
I'm not as sure as you that this difference must mean it's gnuplot that
is wrong ;-)
> Excel Funcion: f(x) = -6.64*x+ 256915
> Gnuplot Function: f(x) = 7.9214e-06*x + 1
This suggests you were *way* off with the startup values you gave
gnuplot --- that's why the value for 'b' never moved at all.
There are a lot of things wrong with your example case:
* your 'x' is a date+time. You don't seem to have used gnuplot's
date/time parsing capabilities in the fragment of gnuplot command script
you show
* gnuplot and Excel use wildly different internal scales for date/time
values, so the expectation of getting numerically equal results is flawed.
* you wrote 'using 1:2' --- that will plot and fit the hour against the
date. Almost certainly not what you wanted.
* the model function (linear dependance of y on time) doesn't fit the
data at all, neither for 'using 1:2', nor for 'using 1:3'.
* the form a*x+b is spectacularly mismatched to a dataset that sits this
far away from the point x=0 (new year 2000 for gnuplot, some thing like
newyear 1900 for Excel, IIRC).
* the fit, once it's been forced to work by fixing most of the above
problems, would have hugely different sizes for parameters a and b:
gnuplot> show func
User-Defined Functions:
f(x)=a*(x-17e7)+1e8*b
gnuplot> a=1 ; b=1; fit f(x) 'date.dat' u 1:3 via a, b
[...]
Final set of parameters Asymptotic Standard Error
======================= ==========================
a = -7.70491e-005 +/- 0.0001626 (211.1%)
b = 1.19202e-005 +/- 2.862e-006 (24.01%)
correlation matrix of the fit parameters:
a b
a 1.000
b 0.996 1.000
Translated to the original form, this fitted function is:
f(x) = (-7+/-16)*1e-5*(x-17e7) + 1e8*(1.2+/-0.3)*1e-5
= (-7e-5 +/- 16e-5) * x + (14000 +/- 27000)
That's nine orders of magnitudes of difference between a and b. This
causes severe numerical problems for the fit.
gnuplot is at least honest with you. It's telling you right away that
this didn't work:
> a = 7.9214e-06 +/- 0.0001624 (2050%)
> b = 1 +/- 2.732e+04 (2.732e+06%)
Errors of 2000 percent and more should be sufficient warning that
something's not right here.
|