loglin
is used to fit loglinear models to multidimensional
contingency tables by Iterative Proportional Fitting.
1 2 
table 
a contingency table to be fit, typically the output from

margin 
a list of vectors with the marginal totals to be fit. (Hierarchical) loglinear models can be specified in terms of these
marginal totals which give the ‘maximal’ factor subsets contained
in the model. For example, in a threefactor model,
The names of factors (i.e., 
start 
a starting estimate for the fitted table. This optional
argument is important for incomplete tables with structural zeros
in 
fit 
a logical indicating whether the fitted values should be returned. 
eps 
maximum deviation allowed between observed and fitted margins. 
iter 
maximum number of iterations. 
param 
a logical indicating whether the parameter values should be returned. 
print 
a logical. If 
The Iterative Proportional Fitting algorithm as presented in
Haberman (1972) is used for fitting the model. At most iter
iterations are performed, convergence is taken to occur when the
maximum deviation between observed and fitted margins is less than
eps
. All internal computations are done in double precision;
there is no limit on the number of factors (the dimension of the
table) in the model.
Assuming that there are no structural zeros, both the Likelihood
Ratio Test and Pearson test statistics have an asymptotic chisquared
distribution with df
degrees of freedom.
Note that the IPF steps are applied to the factors in the order given
in margin
. Hence if the model is decomposable and the order
given in margin
is a running intersection property ordering
then IPF will converge in one iteration.
Package MASS contains loglm
, a frontend to
loglin
which allows the loglinear model to be specified and
fitted in a formulabased manner similar to that of other fitting
functions such as lm
or glm
.
A list with the following components.
lrt 
the Likelihood Ratio Test statistic. 
pearson 
the Pearson test statistic (Xsquared). 
df 
the degrees of freedom for the fitted model. There is no adjustment for structural zeros. 
margin 
list of the margins that were fit. Basically the same
as the input 
fit 
An array like 
param 
A list containing the estimated parameters of the
model. The ‘standard’ constraints of zero marginal sums
(e.g., zero row and column sums for a two factor parameter) are
employed. Only returned if 
Kurt Hornik
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth & Brooks/Cole.
Haberman, S. J. (1972) Loglinear fit for contingency tables—Algorithm AS51. Applied Statistics, 21, 218–225.
Agresti, A. (1990) Categorical data analysis. New York: Wiley.
table
.
loglm
in package MASS for a
userfriendly wrapper.
glm
for another way to fit loglinear models.
1 2 3 4 5 
Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.
Please suggest features or report bugs with the GitHub issue tracker.
All documentation is copyright its authors; we didn't write any of that.