\Header{logLik.lm}{Extract Log-Likelihood from an lm Object}
\keyword{models}{logLik.lm}
\begin{Description}\relax
If \code{REML = FALSE}, returns the log-likelihood value of the linear
model represented by \code{object} evaluated at the estimated
coefficients; else, the restricted log-likelihood evaluated at the
estimated coefficients is returned.\end{Description}
\begin{Usage}
\begin{verbatim}
## S3 method for class 'lm':
logLik(object, REML = FALSE, ...)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{object}] an object inheriting from class \code{"lm"}.
\item[\code{REML}] an optional logical value.  If \code{TRUE} the restricted
log-likelihood is returned, else, if \code{FALSE}, the
log-likelihood is returned.  Defaults to \code{FALSE}.
\item[\code{...}] further arguments to be passed to or from methods.
\end{ldescription}
\end{Arguments}
\begin{Value}
an object of class \code{logLik},
the (restricted) log-likelihood of the linear model represented by
\code{object} evaluated at the estimated coefficients.  Note that
error variance \eqn{\sigma^2}{} is estimated in \code{lm()} and hence
counted as well.\end{Value}
\begin{Author}\relax
Jose Pinheiro and Douglas Bates\end{Author}
\begin{References}\relax
Harville, D.A. (1974).
Bayesian inference for variance components using only error contrasts.
\emph{Biometrika}, \bold{61}, 383--385.\end{References}
\begin{SeeAlso}\relax
\code{\Link{lm}}\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
data(attitude)
(fm1 <- lm(rating ~ ., data = attitude))
logLik(fm1)
logLik(fm1, REML = TRUE)

res <- try(data(Orthodont, package="nlme"))
if(!inherits(res, "try-error")) {
  fm1 <- lm(distance ~ Sex * age, Orthodont)
  print(logLik(fm1))
  print(logLik(fm1, REML = TRUE))
}\end{ExampleCode}
\end{Examples}

