[R-sig-eco] log-linear model and log-likelihood ratio

Kingsford Jones kingsfordjones at gmail.com
Sun Feb 15 01:59:56 CET 2009


Hi Marta,

IIRC, the LRT (which is the first of the 2 tests returned by the loglm
print method, and does use the G2 stat) compares the fitted model to
one that fits perfectly.  Your first model is saturated/fits
perfectly, and leaves no df for the test stat.  See code and output
below.

hth,

Kingsford Jones


 floodplain=data.frame(y=c(15,4,0, 13,8,17),
              position=gl(3,1,6, labels=c("bottom","middle","top")),
              dead_coli=gl(2,3,labels=c("with","without")))

 library(MASS)
 f1 <- loglm(y ~ position*dead_coli, floodplain)
 f2 <- loglm(y~ position + dead_coli, floodplain)

> resid(f1)
Re-fitting to get frequencies and fitted values
        dead_coli
position with without
  bottom    0       0
  middle    0       0
  top       0       0

> f1$lrt # G2 stat
[1] 0

> f1$df # associated df
[1] 0





On Sat, Feb 14, 2009 at 11:25 AM, Marta Rufino
<mrufino at cripsul.ipimar.pt> wrote:
> Dear all,
>
> I am trying learn something (on analysis of frequencies) by reproducing the
> examples from Quinn & Keough book (experimental design...) from chapter 14,
> section 14.3 on log-linear models.
>
> # This would be the data
> floodplain=data.frame(y=c(15,4,0, 13,8,17),
>              position=gl(3,1,6, labels=c("bottom","middle","top")),
>              dead_coli=gl(2,3,labels=c("with","without")))
>
> # The first full model would be (log-linear model to calculate the
> log-likelihood ratio):
> loglm(y ~ position + dead_coli + position:dead_coli, floodplain) # which
> includes interaction.. and does not work, not even if I add a constant of .5
> to y. In the book it is suppose to give: -10.429
>
> # the second reduced model would be (does not work)
> loglm(y~ position + dead_coli, floodplain) #which works, but gives a
> different result from the book. In the book it gives: -19.735
>
> This is needed to calculate G2 statistic (from Sokal and Rohlf) for which I
> could not find anything in R, also.
>
> Any idea about what is wrong or the correct calculations? I looked on Sokal
> and Rohlf, and had the same problem...
>
> Thank you very much e in advance,
> Best wishes,
> Marta
>
> _______________________________________________
> R-sig-ecology mailing list
> R-sig-ecology at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
>



More information about the R-sig-ecology mailing list