Next: lt, Previous: lsmooth, Up: Internal Routines [Contents][Index]

`lsq(`

`x`, `y` [, weights=`w`, cov=`cov`,
err=`err`, chisq=`chisq`, /formal, /reduce])

Returns a linear least-squares fit of

to `y`

.
`x`

must have either the same dimensional structure as
`x`

, 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
`y`

. The model to be fitted is `x`

, where `y` =

(0)*`a`

(...,0) +
`x`

(1)*`a`

(...,1) + ...`x`

stands for the parameters sought from the fit, which are returned by
this function.
`a`

Optionally, a weight can be assigned to each data point, in

. These weights should be equal to the inverse of the
variance associated with each data point.
`w`

If

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
`cov``/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.

If

is specified, then the weighted root-mean-square
value of the residual errors (after subtraction of the model values) is
returned in it.
`err`

If

is specified, then the chi-square value of the fit
is returned in it.
`chisq`

The magnitudes of the (co)variances in

and of
`cov`

are only meaningful if proper weights were specified
in `chisq`

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
`w``1/`

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.
`w`

If no weights were specified, or if the proper normalization of the
values specified in

is not known, then you can derive
formal estimates for the errors on the model parameters by specifying
the `w``/formal`

keyword. In that case, the variance on the data
values is assumed equal to

, where `err`^2*n/(n - 1)`n`

is the number of data points (taken to be equal to the sum of all
elements of

if `w`

is specified), and the
variances on the model parameters are scaled accordingly. (The
correction factor involving `w``n`

is necessary to get an unbiased
estimator.) This corresponds to forcing chi-square equal to the ideal
value of `n - 1`

.

See also: fit

Next: lt, Previous: lsmooth, Up: Internal Routines [Contents][Index]