Skip to content

logLik

1 message · Ben Bolker

#
(previous post bounced due to GPG wrapper)
Daniel Ezra Johnson wrote:
If you count the implicit variance, it has two.
see stats:::logLik.lm : the core is

  val <- 0.5 * (sum(log(w)) - N * (log(2 * pi) + 1 - log(N) +
        log(sum(w * res^2))))

where res are residuals, w are weights, N is the number of points
The likelihood ratio test is asymptotic, so you should use an F test
if you're in a situation where it's appropriate.

x <- rnorm(100)
 > y <- 1+2*x+rnorm(100,sd=1)
Analysis of Variance Table

Model 1: y ~ x
Model 2: y ~ 1
  Res.Df     RSS Df Sum of Sq      F    Pr(>F)
1     98   94.16
2     99  492.44 -1   -398.29 414.54 < 2.2e-16 ***
---
Signif. codes:  0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1


  str() shows that the actual p-value is 5.54e-37
[1] 7.325424e-38
attr(,"nall")
[1] 100
attr(,"nobs")
[1] 100
attr(,"df")
[1] 3
attr(,"class")
[1] "logLik"