Octave has a function ols which find the least squares solution of an
overdetermined linear system. I propose the following function, which
finds the "least abolute deviation" solution - the one that minimizes
the sum of the absolute values of the deviations. It is more work to
find (requiring solution of a linear program), but is more robust to
outliers. See below for references.
The LAD solution is the analog of the median. You will recall that
the median of an odd number of values is well defined, but for an even
number of values we normally add a condition so we get the center of
the interval between the centermost values. This implementation of
the LAD does not have this kind of rule. If there is more than one
solution that minimizes the sum of absolute values of the deviations,
it doesn't attempt to return the "middle" one.
- Jim Van Zandt