LinearFit "variancecovariance" matrix calculation method?

Dear all,

 

I'm trying to duplicate by hand the variancecovariance matrix (and stanard error vector) of a simple LinearFit of data (2nd order function of form a + bx + cx^2), using the inverse of the curvature matrix as in Chapter 15 "Modeling of Data" of the Numerical Algorithms book 3rd Edition, or the paper by Keith H. burrell "Error analysis for parameters determined in nonlinwear least-squares fits", American journal of Physics, Vol. 58, No. 2, 160-164 (1990). Unfortunately, I cannot get the same answer, even with simple unweighted examples.

The Maple help manual gives a complete example in the section "Statistics[LinearFit]-fit a linear model function to data". What I do by hand is calculate the curvature matrix as follows (LaTeX notation):

 

\alpha_{kj} = \sum_{i=0}^{N-1} \frac{X_j(x_i) X_k(x_i)}{\sigma_i^2}

 

where there are N data points with x the independent variable, and the sigma_i are the standard errors for each of the dependent y values (the dependent values themselves do not appear in the above equation). For the example, I set these sigma to unity. The basis functions X_j (and X_k) are 1, x^ and x^2 for my quadratic fitting.

I therefore construct the curvature matrix made up of the terms above, and invert it to obtain the covariance matrix, which I expect to be the same as that given in the output of Maple for such fitting, as the "variancecovariance matrix", and the square root of the diagonal would then be the "standard error vector". However, my results, either for the simple Maple example, or for an example with weights, are not the same.

 

I suspect I have either misunderstood the hand calculation method entirely, or else I misunderstand what Maple has done and is presenting to me in the output.

Any tips would be very much appreciated.

 

Best regards,

  Gernot Hassenpflug, NICT, Tokyo

Variance-Covariance matrix

Reproducing the same example as in the Helppage of Statistics[LinearFit], we first write the postulated model function:

with(linalg): f:=b[1]+b[2]*p+b[3]*p^2:

where p is the independent variable, and b the parameter vector. We then compute the vector of the derivatives of f with respect to the parameters, and then the transposed vector:

gT:=[seq(diff(f,b[i]),i=1..3)]: g:=transpose(gT):

Neglecting the need of an optimization procedure in order us to find the parameters, let’s assume that the parameter-vector is the one appearing in Maple Help Page, while r is the vector of the data:

b:=[1.95999999999999996,0.165000000000000063,0.110714285714285710]:     r:=[1, 2, 3, 4, 5, 6]:

We then define the procedure atab to find matrix X:

A:=multiply(gT,g): m:=nops(r): atab:=proc() global r, p, A, m; local i; X1:=[[0,0,0],[0,0,0],[0,0,0]]; X:=apply(X1,table); for i to m do p:=r[i]; X:=X+apply(A,table); end do; end proc:

Eventually, the variance-covariance matrix (covmatrix) can be evaluated by:

C:=evalm(atab());

Corig:=evalm(inverse(C));

of:=1.28771428571428581: covmatrix:=evalm(of/(m-nops(b))*Corig);

where of is the residuals sums of squares, as appearing in Maple Help Page.

 I understand that procedure atab is not the best in the world to evaluate the matrix, but I am not so ashamed not to upload it.

You can find theory for the above analysis in Himmelblau (1970), Process Analysis by Statistical Methods, pp. 197-198 (for Nonlinear Models).

pantole 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
}