\Header{lm}{Fitting Linear Models}
\alias{lm.fit}{lm}
\alias{lm.wfit}{lm}
\alias{lm.fit.null}{lm}
\alias{lm.wfit.null}{lm}
\keyword{regression}{lm}
\begin{Usage}
\begin{verbatim}
lm(formula, data, subset, weights, na.action=na.omit,
   method="qr", model=TRUE, singular.ok = TRUE)

lm.fit[.null] (x, y,    method = "qr", tol = 1e-7, ...)
lm.wfit[.null](x, y, w, method = "qr", tol = 1e-7, ...)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\texttt{formula}] a symbolic description of the model to be fit.
The details of model specification are given below.
\item[\texttt{data}] an optional data frame containing the variables
in the model.  By default the variables are taken from
the environment which \texttt{lm} is called from.
\item[\texttt{subset}] an optional vector specifying a subset of observations
to be used in the fitting process.
\item[\texttt{weights}] an optional vector of weights to be used
in the fitting process.
\item[\texttt{na.action}] a function which indicates what should happen
when the data contain \texttt{NA}s.  The default action (\texttt{na.omit})
is to omit any incomplete observations.
The alternative action \texttt{na.fail} causes \texttt{lm} to
print an error message and terminate if there are any incomplete
observations.
\item[\texttt{model}] logical.  If \texttt{TRUE} (default), the model.frame is also
returned.
\item[\texttt{singular.ok}] logical, defaulting to
\texttt{TRUE}. \emph{\texttt{FALSE} is not yet implemented}.
\item[\texttt{method}] currently, only \texttt{method="qr"} is supported.
\item[\texttt{tol}] tolerance for the \texttt{\Link{qr}} decomposition.  Default is 1e-7.
\item[\texttt{...}] currently disregarded.
\end{ldescription}
\end{Arguments}
\begin{Description}
\texttt{lm} is used to fit linear models.
It can be used to carry out regression,
single stratum analysis of variance and
analysis of covariance.

Models for \texttt{lm} are specified symbolically.
A typical model has the form
\texttt{response $\,\tilde{\,}$ terms} where \texttt{response} is the (numeric)
response vector and \texttt{terms} is a series of terms which
specifies a linear predictor for \texttt{response}.
A terms specification of the form \texttt{first+second}
indicates all the terms in \texttt{first} together
with all the terms in \texttt{second} with duplicates
removed.
A specification of the form \texttt{first:second} indicates the
the set of terms obtained by taking the interactions of
all terms in \texttt{first} with all terms in \texttt{second}.
The specification \texttt{first*second} indicates the \emph{cross}
of \texttt{first} and \texttt{second}.
This is the same as \texttt{first+second+first:second}.\end{Description}
\begin{Value}
\texttt{lm} returns an object of \texttt{\Link{class}} \texttt{"lm"}.

The functions \texttt{summary} and \texttt{\Link{anova}} are used to
obtain and print a summary and analysis of variance table of the results.
The generic accessor functions \texttt{coefficients},
\texttt{effects}, \texttt{fitted.values} and \texttt{residuals}
extract various useful features of the value returned by \texttt{lm}.\end{Value}
\begin{SeeAlso}
\texttt{\Link{summary.lm}} for summaries and \texttt{\Link{anova.lm}} for
the ANOVA table.
The generic functions \texttt{\Link{coefficients}}, \texttt{\Link{effects}},
\texttt{\Link{residuals}}, \texttt{\Link{fitted.values}};
\texttt{\Link{lm.influence}} for regression diagnostics, and
\texttt{\Link{glm}} for \bold{generalized} linear models.\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
## Annette Dobson (1990) "An Introduction to Statistical Modelling".
## Page 9: Plant Weight Data.
ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
group <- gl(2,10,20,labels=c("Ctl","Trt"))
weight <- c(ctl,trt)
anova(lm.D9 <- lm(weight~group))
summary(lm.D90 <- lm(weight ~ group -1))# omitting intercept
summary(resid(lm.D9) - resid(lm.D90)) #- residuals almost identical

plot(lm.D9)# Residuals, Fitted,..
\end{ExampleCode}
\end{Examples}

