% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/seq_loglm.R
\name{seq_loglm}
\alias{seq_loglm}
\title{Sequential Loglinear Models for an N-way Table}
\usage{
seq_loglm(
  x,
  type = c("joint", "conditional", "mutual", "markov", "saturated"),
  marginals = 1:nf,
  vorder = 1:nf,
  k = NULL,
  prefix = NULL,
  fitted = TRUE,
  ...
)
}
\arguments{
\item{x}{a contingency table in array form, with optional category labels specified in the dimnames(x) attribute,
or else a data.frame in frequency form, with the frequency variable named \code{"Freq"}.}

\item{type}{type of sequential model to fit, a character string. One of \code{"joint"}, \code{"conditional"},
\code{"mutual"}, \code{"markov"}, or \code{"saturated"}.}

\item{marginals}{which marginal sub-tables to fit? A vector of a (sub)set of the integers, \code{1:nf} where
\code{nf} is the number of factors in the full n-way table.}

\item{vorder}{order of variables, a permutation of the integers \code{1:nf}, used to reorder the variables in
the original table for the purpose of fitting sequential marginal models.}

\item{k}{conditioning variable(s) for \code{type} = \code{"joint"}, \code{"conditional"} or Markov chain order
for \code{type} = \code{"markov"}}

\item{prefix}{prefix used to give names to the sequential models. If \code{NULL} (the default),
uses an abbreviation of \code{type}: \code{"joint"}, \code{"cond"}, \code{"mutual"}, \code{"markov"}, or \code{"sat"}.}

\item{fitted}{argument passed to \code{loglm} to store the fitted values in the model objects}

\item{\dots}{other arguments, passed down}
}
\value{
An object of class \code{"loglmlist"}, each of which is a class \code{"loglm"} object
}
\description{
This function takes an n-way contingency table and fits a series of
sequential models to the 1-, 2-, ... n-way marginal tables, corresponding to
a variety of types of loglinear models.
}
\details{
Sequential marginal models for an n-way tables begin with the model of
equal-probability for the one-way margin (equivalent to a
\code{\link[stats]{chisq.test}}) and add successive variables one at a time
in the order specified by \code{vorder}.

All model types give the same result for the two-way margin, namely the test
of independence for the first two factors.

Sequential models of \emph{joint independence} (\code{type="joint"}) have a
particularly simple interpretation, because they decompose the likelihood
ratio test for the model of mutual independence in the full n-way table, and
hence account for "total" association in terms of portions attributable to
the conditional probabilities of each new variable, given all prior
variables.
}
\note{
One-way marginal tables are a bit of a problem here, because they
cannot be fit directly using \code{\link[MASS]{loglm}}. The present version
uses \code{\link[stats]{loglin}}, and repairs the result to look like a
\code{loglm} object (sort of).
}
\examples{

data(Titanic, package="datasets")
# variables are in the order Class, Sex, Age, Survived

# Models of joint independence
tit.joint <- seq_loglm(Titanic, type = "joint")

# compare the models
LRstats(tit.joint)

#' # Models of conditional independence
tit.cond <- seq_loglm(Titanic, type = "conditional")

# compare the models
LRstats(tit.cond)



}
\references{
These functions were inspired by the original SAS implementation
of mosaic displays, described in the \emph{User's Guide},
\url{http://www.datavis.ca/mosaics/mosaics.pdf}
}
\seealso{
\code{\link{loglin-utilities}} for descriptions of sequential
models, \code{\link{conditional}}, \code{\link{joint}},
\code{\link{mutual}}, \dots{}

\code{\link{loglmlist}}

Other loglinear models:
\code{\link[=assoc_graph]{assoc_graph()}},
\code{\link[=get_model]{get_model()}},
\code{\link[=glmlist]{glmlist()}},
\code{\link[=joint]{joint()}},
\code{\link[=plot.assoc_graph]{plot.assoc_graph()}}
}
\author{
Michael Friendly
}
\concept{loglinear models}
\keyword{models}
