|
From: Isao S. <sa...@bi...> - 2004-04-05 04:38:51
|
Dear maintainers of gnuplot.
In fit.c: The covar matrix is calculated base on err_data if given by a
user. Thus, scaling of parameter errors occurs twice and cancels out
each other if err_data are explicitly given.
For example, if you fit the data,
# fit data (data.dat)
0 1.1 100
1 1.9 100
2 5.1 100
3 9.9 100
4 17.1 100
With the function f(x) = a * x**2 + b, results of fitting from "fit f(x)
'data.dat' using 1:2 via a, b" and "fit f(x) 'data.dat' using 1:2:3 via
a, b" are identical (except for sum of squares of residuals). However,
"Asymptotic Standard Error" of parameters should increase as errors
increase.
I think this bug can be resolved with a patch attached below.
I don't subscribe this mailing list. Please inform me if there is
something with this patch.
Regards.
----
Isao Sakane <sa...@bi...>
Tottori University, Faculty of Engineering, Dept. of Biotechnology,
Koyamacyo-minami 4-101, Tottori-city, Tottori, Japan. ZIP:680-8552
----
Hear is a patch.
--- fit.c.old 2004-04-05 09:22:07.000000000 +0900
+++ fit.c 2004-04-05 12:09:29.000000000 +0900
@@ -745,7 +745,17 @@
covar = C + num_data;
Invert_RtR(C, covar, num_params);
- /* calculate unscaled parameter errors in dpar[]: */
+ if (columns <= 2) {
+ /* scale covar matrix based on chisq */
+ chisq /= (num_data - num_params);
+ for (i = 0; i < num_params; i++) {
+ /* only lower triangle needs to be handled */
+ for (j = 0; j <= i; j++)
+ covar[i][j] *= chisq;
+ }
+ }
+
+ /* calculate parameter errors in dpar[]: */
dpar = vec(num_params);
for (i = 0; i < num_params; i++) {
/* FIXME: can this still happen ? */
@@ -761,11 +771,6 @@
covar[i][j] /= dpar[i] * dpar[j];
}
- /* scale parameter errors based on chisq */
- chisq = sqrt(chisq / (num_data - num_params));
- for (i = 0; i < num_params; i++)
- dpar[i] *= chisq;
-
Dblf("Final set of parameters Asymptotic Standard
Error\n");
Dblf("======================= =======================
===\n\n");
|