covar method
If the minimisation uses the weighted least-squares function f_i = (Y(x, t_i) - y_i) / \sigma_i then the covariance matrix gives the statistical error on the best-fit parameters resulting from the Gaussian errors \sigma_i onthe underlying data y_i. This can be verified from the relation \delta f = J \delta c and the fact that the fluctuations in f from the data y_i are normalised by \sigma_i and so satisfy <\delta f \delta f^T> = I. For an unweighted least-squares function f_i = (Y(x, t_i) - y_i) t he covariance matrix above should be multiplied by the variance of the residuals about the best-fit \sigma^2 = \sum (y_i - Y(x,t_i))^2 / (n-p) to give the variance-covariance matrix \sigma^2 C . This estimates the statistical error on the best-fit parameters from the scatter of the underlying data.
Implementation
List<List<double>> covar(List<double> params) {
List<List<double>> covar1;
List<List<double>> hes = hessian(params);
// the following limit is arbitrary, BG
if ((numeric.sumM(hes)).abs() > 1.0e-8) {
covar1 = numeric.invMatrix(hes);
} else {
covar1 = numeric.createMatrix(hes.length, hes[0].length, 0.0);
}
if (!weightedFit) {
covar1 = numeric.dotCM(totalError(), covar1);
}
return covar1;
}