I am using the lsqcurvefit function in Matlab to model some experimental data. The data takes a specific shape and so the algorithm is just adjusting the coefficients of this shape to change its amplitude etc.
The model works fine and gives a good fit (I have calculated chi-sq). Other implementations of the Levenberg-Marquardt algorithm give covariance as an output but in Matlab it is not an option for output (only 1st order optimality, no of iterations, Lambda and Jaccobian along with the bounds) .
Does anybody know how to calculate the covariance matrix either from the outputs given (I'm not 100% on what use lambda and jaccobian could be or 1st order optimallity) by lsqcurvefit or independantly?
Any help would be greatly appreciated, thanks!
I think I have solved this myself but will post how here if anyone else is having the same trouble.
The covariance matrix can be calculated from the Jacobian by:
C = inv(J'*J)*MSE
Where MSE is mean-square error:
MSE = (R'*R)/(N-p)
Where R = residuals, N = number of observations, p = number of coefficients estimated.
Or MSE can be calculated via iteration.
Hopefully this will help someone else in the future.
If anyone spots error please let me know. Thanks