\HeaderA{lsfit}{Find the Least Squares Fit}{lsfit}
\keyword{regression}{lsfit}
\begin{Description}\relax
The least squares estimate of \bold{\eqn{\beta}{b}} in the model
\deqn{\bold{Y} = \bold{X \beta} + \bold{\epsilon}}{y = X b + e}
is found.
\end{Description}
\begin{Usage}
\begin{verbatim}
lsfit(x, y, wt = NULL, intercept = TRUE, tolerance = 1e-07, yname = NULL)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] a matrix whose rows correspond to cases and whose columns
correspond to variables.
\item[\code{y}] the responses, possibly a matrix if you want to fit multiple
left hand sides.
\item[\code{wt}] an optional vector of weights for performing weighted least squares.
\item[\code{intercept}] whether or not an intercept term should be used.
\item[\code{tolerance}] the tolerance to be used in the matrix decomposition.
\item[\code{yname}] names to be used for the response variables.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
If weights are specified then a weighted least squares is performed
with the weight given to the \emph{j}th case specified by the \emph{j}th
entry in \code{wt}.

If any observation has a missing value in any field, that observation
is removed before the analysis is carried out.
This can be quite inefficient if there is a lot of missing data.

The implementation is via a modification of the LINPACK subroutines
which allow for multiple left-hand sides.
\end{Details}
\begin{Value}
A list with the following named components:
\begin{ldescription}
\item[\code{coef}] the least squares estimates of the coefficients in
the model (\bold{\eqn{\beta}{b}} as stated above).
\item[\code{residuals}] residuals from the fit.
\item[\code{intercept}] indicates whether an intercept was fitted.
\item[\code{qr}] the QR decomposition of the design matrix.
\end{ldescription}
\end{Value}
\begin{References}\relax
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)
\emph{The New S Language}.
Wadsworth \& Brooks/Cole.
\end{References}
\begin{SeeAlso}\relax
\code{\LinkA{lm}{lm}} which usually is preferable;
\code{\LinkA{ls.print}{ls.print}}, \code{\LinkA{ls.diag}{ls.diag}}.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}

##-- Using the same data as the lm(.) example:
lsD9 <- lsfit(x = unclass(gl(2,10)), y = weight)
ls.print(lsD9)
\end{ExampleCode}
\end{Examples}

