Comment on Curvefit

The Curvefit application works great. A notation in the Curvefit documentation bothers me, and I think is misleading. The Global Output _cv_InfoMatrix is said to be the cross product of the first derivatives. It refers to Section 3.2.1. At the top of page 3-27 it says G'G is stored in the matrix. However it contains the inverse of cov, the returned covariance matrix of the coefficients, as the following example illustrates.

new; cls;
// simulated example 1 in Nonlinear Statistical Methods by Ronald Gallant, 1987
output file=curvefit_typo.out reset;
library cvfit;
#include cvfit.ext
CurveFitSet;

n = 500;
parm0 = {0,1,-1,-0.5};
sig20 = 0.001;
state1 = 75551107;
state2 = 85121119;
state3 = 29959447;

{ x1,state1 } = rndu(n,1,state1);
x1 = (x1 .>= 0.5); 
x2 = ones(n,1); 
{ x3,state2 } = rndu(n,1,state2); 
x = x1~x2~x3;
{ epsilon, state3 } = rndn(n, 1, state3); 
y = parm0[1]*x1 + parm0[2]*x2 + parm0[4]*exp(parm0[3].*x3) + sqrt(sig20).*epsilon;

CurveFitClr; 
{b,sighat2,g,V,retcode}=curvefit("", y, x, &xm1_gallant, parm0);
_cv_GradProc=&grad_uc;
""; "V"; V;

info = _cv_InfoMatrix;
invinfo = invpd(info);
""; "inv(_cv_InfoMatrix)";
invinfo;

gmat = grad_uc(b, x);
cov = sighat2.*invpd(gmat'gmat); 
""; "inv(cov)";
cov;

proc (1) = xm1_gallant(b, x); 
retp(b[1]*x[.,1] + b[2]*x[.,2] + b[4]*exp(b[3].*x[.,3])); 
endp;

proc (1) = grad_uc(b, x); 
local g;
g = x[.,1]~x[.,2]~(b[4] .* x[.,3] .* exp(b[3].*x[.,3]))~(exp(b[3].*x[.,3]));
retp(g); 
endp;
end;

With output

V

8.0948379e-06 -3.6844297e-08 9.8550578e-06 -3.6474411e-06 
-3.6844297e-08 0.0021533593 0.0057820503 -0.0020045045 
9.8550578e-06 0.0057820503 0.015751500 -0.0053465465 
-3.6474411e-06 -0.0020045045 -0.0053465465 0.0018797061

inv(_cv_InfoMatrix)

8.0948379e-06 -3.6844297e-08 9.8550578e-06 -3.6474411e-06 
-3.6844297e-08 0.0021533593 0.0057820503 -0.0020045045 
9.8550578e-06 0.0057820503 0.015751500 -0.0053465465 
-3.6474411e-06 -0.0020045045 -0.0053465465 0.0018797061

inv(cov)

8.0948466e-06 -3.6840840e-08 9.8550726e-06 -3.6474462e-06 
-3.6840840e-08 0.0021533594 0.0057820504 -0.0020045045 
9.8550726e-06 0.0057820504 0.015751500 -0.0053465466 
-3.6474462e-06 -0.0020045045 -0.0053465466 0.0018797062

Your Answer


You must login to post answers.

Have a Specific Question?

Get a real answer from a real person

Need Support?

Get help from our friendly experts.

Try GAUSS for 14 days for FREE

See what GAUSS can do for your data

© Aptech Systems, Inc. All rights reserved.

Privacy Policy