lsq(x, y [, weights=w, cov=cov,
err=err, chisq=chisq, /formal, /reduce])
Returns a linear least-squares fit of
x must have either the same dimensional structure as
y, or the same plus one more dimension. In the former
case, the number of parameters to be fitted is taken equal to 1,
otherwise it is equal to the number of elements in the last dimension of
x. The model to be fitted is
x(...,1) + ...
stands for the parameters sought from the fit, which are returned by
Optionally, a weight can be assigned to each data point, in
w. These weights should be equal to the inverse of the
variance associated with each data point.
cov is specified, then by default a covariance matrix of
the parameters of the fit is returned in it, with the variances on the
diagonal and the covariances in the off-diagonal elements. If
/reduce is specified, then a reduced covariance matrix is
returned instead, in which the diagonal elements contain the standard
deviations, the off-diagonal part that contains most of the first
dimension contains cross-correlation coefficients, and the off-diagonal
part that contains most of the second dimension contains the covariances
(the same as when
/reduce is not specified). The matrix is
square in any case.
err is specified, then the weighted root-mean-square
value of the residual errors (after subtraction of the model values) is
returned in it.
chisq is specified, then the chi-square value of the fit
is returned in it.
The magnitudes of the (co)variances in
cov and of
chisq are only meaningful if proper weights were specified
w as described above. In that case, chi-square should
ideally be equal to the number of data points minus one. If the
chi-square is much smaller than that, then the variances
1/w were apparently overestimated. If the
chi-square is much greater than that, then either the variances were
underestimated, or the linear model is not suitable for the data.
If no weights were specified, or if the proper normalization of the
values specified in
w is not known, then you can derive
formal estimates for the errors on the model parameters by specifying
/formal keyword. In that case, the variance on the data
values is assumed equal to
err^2*n/(n - 1), where
is the number of data points (taken to be equal to the sum of all
w is specified), and the
variances on the model parameters are scaled accordingly. (The
correction factor involving
n is necessary to get an unbiased
estimator.) This corresponds to forcing chi-square equal to the ideal
n - 1.
See also: fit