logLik.lm {base} | R Documentation

## Extract Log-Likelihood from an lm Object

### Description

If `REML = FALSE`, returns the log-likelihood value of the linear model represented by `object` evaluated at the estimated coefficients; else, the restricted log-likelihood evaluated at the estimated coefficients is returned.

### Usage

    ## S3 method for class 'lm':
    logLik(object, REML = FALSE, ...)

### Arguments

`object` | an object inheriting from class `"lm"`.
`REML` | an optional logical value. If `TRUE` the restricted log-likelihood is returned, else, if `FALSE`, the log-likelihood is returned. Defaults to `FALSE`.
`...` | further arguments to be passed to or from methods.

### Value

an object of class `logLik`, the (restricted) log-likelihood of the linear model represented by `object` evaluated at the estimated coefficients. Note that error variance σ^2 is estimated in `lm()` and hence counted as well.

### Author(s)

Jose Pinheiro and Douglas Bates

### References

Harville, D.A. (1974). Bayesian inference for variance components using only error contrasts. Biometrika, 61, 383–385.

### See Also

`lm`

### Examples

    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))
    }

[Package Contents]