|
From: Maurice Al-K. <mau...@mo...> - 2005-05-09 12:22:54
|
Hi,
i have a problem with gnuplot 4.0 and Linear Regression. I got different
values between MS excel and gnuplot.
Excel Funcion: f(x) = -6.64*x+ 256915
Gnuplot Function: f(x) = 7.9214e-06*x + 1
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++
Iteration 0
WSSR : 4.47249e+18 delta(WSSR)/WSSR : 0
delta(WSSR) : 0 limit for stopping : 1e-05
lambda : 1.18969e+08
initial set of free parameter values
a = 1
b = 1
/
Iteration 1
WSSR : 4.45073e+13 delta(WSSR)/WSSR : -100488
delta(WSSR) : -4.47245e+18 limit for stopping : 1e-05
lambda : 1.18969e+07
resultant parameter values
a = 0.00316247
b = 1
/
Iteration 2
WSSR : 1.7563e+07 delta(WSSR)/WSSR : -2.53415e+06
delta(WSSR) : -4.45073e+13 limit for stopping : 1e-05
lambda : 1.18969e+06
resultant parameter values
a = 8.02123e-06
b = 1
/
Iteration 3
WSSR : 1.75184e+07 delta(WSSR)/WSSR : -0.0025441
delta(WSSR) : -44568.6 limit for stopping : 1e-05
lambda : 118969
resultant parameter values
a = 7.9214e-06
b = 1
*/
Iteration 4
WSSR : 1.75184e+07 delta(WSSR)/WSSR : -4.253e-16
delta(WSSR) : -7.45058e-09 limit for stopping : 1e-05
lambda : 118969
resultant parameter values
a = 7.9214e-06
b = 1
After 4 iterations the fit converged.
final sum of squares of residuals : 1.75184e+07
rel. change during last iteration : -4.253e-16
degrees of freedom (ndf) : 156
rms of residuals (stdfit) = sqrt(WSSR/ndf) : 335.108
variance of residuals (reduced chisquare) = WSSR/ndf : 112297
Final set of parameters Asymptotic Standard Error
======================= ==========================
a = 7.9214e-06 +/- 0.0001624 (2050%)
b = 1 +/- 2.732e+04 (2.732e+06%)
correlation matrix of the fit parameters:
a b
a 1.000
b -1.000 1.000
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++
f(x)=a*x+b
fit f(x) 'data_time_mod.txt' using 1:2via a,b
plot 'data_time_mod.txt' using 1:2 title "Test" lt 6 lw 3 with points,f(x)
title "Lineare Regresion" lt 2 lw 1
#data_time_mod.txt
# x y
#Datum Delta
28.4.05 1:00 1126
28.4.05 2:00 1050
28.4.05 3:00 1332
28.4.05 4:00 1104
28.4.05 5:00 1047
28.4.05 6:00 1260
28.4.05 7:00 1477
28.4.05 8:00 1461
28.4.05 9:00 1356
28.4.05 10:00 1210
28.4.05 11:00 1200
28.4.05 12:00 1225
28.4.05 13:00 1193
28.4.05 14:00 1201
28.4.05 15:00 1229
28.4.05 16:00 1227
28.4.05 17:00 1221
28.4.05 18:00 1263
28.4.05 19:00 1258
28.4.05 20:00 1494
28.4.05 21:00 1216
28.4.05 22:00 1335
28.4.05 23:00 3586
29.4.05 0:00 1188
29.4.05 1:00 1216
29.4.05 2:00 1393
29.4.05 3:00 2081
29.4.05 4:00 1151
29.4.05 5:00 2231
29.4.05 6:00 1295
29.4.05 7:00 1128
29.4.05 8:00 1246
29.4.05 9:00 1227
29.4.05 10:00 1190
29.4.05 11:00 1207
29.4.05 12:00 1198
29.4.05 13:00 1189
29.4.05 14:00 1196
29.4.05 15:00 1209
29.4.05 16:00 1217
29.4.05 17:00 1227
29.4.05 18:00 1271
29.4.05 19:00 1245
29.4.05 20:00 1262
29.4.05 21:00 1198
29.4.05 22:00 1380
29.4.05 23:00 1784
30.4.05 0:00 1111
30.4.05 1:00 1187
30.4.05 2:00 1398
30.4.05 3:00 1988
30.4.05 4:00 1135
30.4.05 5:00 2299
30.4.05 6:00 1210
30.4.05 7:00 1072
30.4.05 8:00 1214
30.4.05 9:00 1300
30.4.05 10:00 1267
30.4.05 11:00 1265
30.4.05 12:00 1235
30.4.05 13:00 1238
30.4.05 14:00 1257
30.4.05 15:00 1262
30.4.05 16:00 1253
30.4.05 17:00 1263
30.4.05 18:00 1389
30.4.05 19:00 1132
30.4.05 20:00 1169
30.4.05 21:00 1147
30.4.05 22:00 1472
30.4.05 23:00 1967
1.5.05 0:00 1121
1.5.05 1:00 1091
1.5.05 2:00 1490
1.5.05 3:00 2112
1.5.05 4:00 1230
1.5.05 5:00 2204
1.5.05 6:00 1274
1.5.05 7:00 1160
1.5.05 8:00 1189
1.5.05 9:00 2110
1.5.05 10:00 1124
1.5.05 11:00 1107
1.5.05 12:00 1102
1.5.05 13:00 1148
1.5.05 14:00 1155
1.5.05 15:00 1128
1.5.05 16:00 1102
1.5.05 17:00 1144
1.5.05 18:00 1424
1.5.05 19:00 1086
1.5.05 20:00 1151
1.5.05 21:00 1128
1.5.05 22:00 1409
1.5.05 23:00 1757
2.5.05 0:00 1062
2.5.05 1:00 1114
2.5.05 2:00 1297
2.5.05 3:00 2146
2.5.05 4:00 1075
2.5.05 5:00 2022
2.5.05 6:00 1106
2.5.05 7:00 1093
2.5.05 8:00 1246
2.5.05 9:00 1259
2.5.05 10:00 1283
2.5.05 11:00 1197
2.5.05 12:00 1191
2.5.05 13:00 1190
2.5.05 14:00 1198
2.5.05 15:00 1367
2.5.05 16:00 1183
2.5.05 17:00 1196
2.5.05 18:00 1254
2.5.05 19:00 1218
2.5.05 20:00 1228
2.5.05 21:00 1174
2.5.05 22:00 1332
2.5.05 23:00 1846
3.5.05 0:00 1086
3.5.05 1:00 1181
3.5.05 2:00 1392
3.5.05 3:00 1935
3.5.05 4:00 1065
3.5.05 5:00 2305
3.5.05 6:00 1207
3.5.05 7:00 1163
3.5.05 8:00 1254
3.5.05 9:00 1219
3.5.05 10:00 1199
3.5.05 11:00 1207
3.5.05 12:00 1212
3.5.05 13:00 1208
3.5.05 14:00 1193
3.5.05 15:00 1199
3.5.05 16:00 1203
3.5.05 17:00 1202
3.5.05 18:00 1256
3.5.05 19:00 1216
3.5.05 20:00 1239
3.5.05 21:00 1158
3.5.05 22:00 1358
3.5.05 23:00 1877
4.5.05 0:00 1140
4.5.05 1:00 1065
4.5.05 2:00 1500
4.5.05 3:00 1887
4.5.05 4:00 1092
4.5.05 5:00 2131
4.5.05 6:00 1243
4.5.05 7:00 1139
4.5.05 8:00 1258
4.5.05 9:00 1219
4.5.05 10:00 1205
4.5.05 11:00 1191
4.5.05 12:00 1206
4.5.05 13:00 1193
4.5.05 14:00 1214
**************************************************************************************************
** eSafe scanned this email for viruses, vandals and malicious content. **
************************************************************************************************** |
|
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.
|