[R] fitting the null loglinear model with MASS::loglm??

Michael Friendly friendly at yorku.ca
Sat Jul 6 14:30:56 CEST 2013

The null loglinear model is an intercept-only model for log frequency, 
log(f) = \mu
For a one-way table the test of the null model is the same as the 
This can be fit using loglin(), but I don't think there is any way to 
specify this using MASS::loglm

 > t1<- margin.table(Titanic,1)
 > t1
  1st  2nd  3rd Crew
  325  285  706  885

 > loglin(t1, NULL)
0 iterations: deviation
[1] 475.8113

[1] 467.8069

[1] 3


 > chisq.test(t1)

         Chi-squared test for given probabilities

data:  t1
X-squared = 467.8069, df = 3, p-value < 2.2e-16

The problem is that loglm() allows the 'convenience' of using integers 
rather than names to specify
terms in the model, e.g., 1+2+3, so there is no way AFAICS to specify an 
intercept-only model.
That is, below, the model ~1 is actually the saturated model for the 
one-way table.

 > loglm(~NULL, t1)
Error in denumerate.formula(formula) : node stack overflow
 > loglm(~0, t1)
Error in double(nmar) : vector size cannot be NA/NaN
 > loglm(~1, t1)
loglm(formula = ~1, data = t1)

                  X^2 df P(> X^2)
Likelihood Ratio   0  0        1
Pearson            0  0        1

Michael Friendly     Email: friendly AT yorku DOT ca
Professor, Psychology Dept. & Chair, Quantitative Methods
York University      Voice: 416 736-2100 x66249 Fax: 416 736-5814
4700 Keele Street    Web:   http://www.datavis.ca
Toronto, ONT  M3J 1P3 CANADA

More information about the R-help mailing list