logLik {stats} | R Documentation |
This function is generic; method functions can be written to handle
specific classes of objects. Classes which already have methods for
this function include: glm
, lm
, nls
, Arima
and gls
, lme
and others in package nlme.
logLik(object, ...)
## S3 method for class 'lm'
logLik(object, REML = FALSE, ...)
object |
any object from which a log-likelihood value, or a contribution to a log-likelihood value, can be extracted. |
... |
some methods for this generic function require additional arguments. |
REML |
an optional logical value. If |
For a "glm"
fit the family
does not have to specify
how to calculate the log-likelihood, so this is based on the
family's aic()
function to compute the AIC. For the
gaussian
, Gamma
and
inverse.gaussian
families it assumed that the dispersion
of the GLM is estimated has been counted as a parameter in the AIC
value, and for all other families it is assumed that the dispersion is
known.
Note that this procedure is not completely accurate for the gamma and inverse gaussian families, as the estimate of dispersion used is not the MLE.
For "lm"
fits it is assumed that the scale has been estimated
(by maximum likelihood or REML), and all the constants in the
log-likelihood are included.
Returns an object, say r
, of class logLik
which is a
number with attributes, attr(r, "df")
(degrees of
freedom) giving the number of (estimated) parameters in the model.
There is a simple print
method for logLik
objects.
The details depend on the method function used; see the appropriate documentation.
Jose Pinheiro and Douglas Bates
For logLik.lm
:
Harville, D.A. (1974). Bayesian inference for variance components using only error contrasts. Biometrika, 61, 383–385.
logLik.gls
, logLik.lme
, in
package nlme, etc.
x <- 1:5
lmx <- lm(x ~ 1)
logLik(lmx) # using print.logLik() method
utils::str(logLik(lmx))
## lm method
(fm1 <- lm(rating ~ ., data = attitude))
logLik(fm1)
logLik(fm1, REML = TRUE)
res <- try(utils::data(Orthodont, package="nlme"))
if(!inherits(res, "try-error")) {
fm1 <- lm(distance ~ Sex * age, Orthodont)
print(logLik(fm1))
print(logLik(fm1, REML = TRUE))
}