# lsfit

##### Find the Least Squares Fit

The least squares estimate of **\(\beta\)** in the model
$$\bold{Y} = \bold{X \beta} + \bold{\epsilon}$$
is found.

- Keywords
- regression

##### Usage

```
lsfit(x, y, wt = NULL, intercept = TRUE, tolerance = 1e-07,
yname = NULL)
```

##### Arguments

- x
a matrix whose rows correspond to cases and whose columns correspond to variables.

- y
the responses, possibly a matrix if you want to fit multiple left hand sides.

- wt
an optional vector of weights for performing weighted least squares.

- intercept
whether or not an intercept term should be used.

- tolerance
the tolerance to be used in the matrix decomposition.

- yname
names to be used for the response variables.

##### Details

If weights are specified then a weighted least squares is performed
with the weight given to the *j*th case specified by the *j*th
entry in `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.

##### Value

A list with the following named components:

the least squares estimates of the coefficients in
the model (**\(\beta\)** as stated above).

residuals from the fit.

indicates whether an intercept was fitted.

the QR decomposition of the design matrix.

##### References

Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)
*The New S Language*.
Wadsworth & Brooks/Cole.

##### See Also

##### Examples

`library(stats)`

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

*Documentation reproduced from package stats, version 3.6.1, License: Part of R 3.6.1*