% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/get_model.R
\name{get_model}
\alias{get_model}
\alias{get_models}
\title{Extract Model Formulas from Model Objects or Model Lists}
\usage{
get_model(x, type = c("brackets", "formula"), abbrev = FALSE, ...)

get_models(x, type = c("brackets", "formula"), abbrev = FALSE, ...)
}
\arguments{
\item{x}{For \code{get_model()}: a \code{loglm} or \code{glm} object.
For \code{get_models()}: a \code{glmlist} or \code{loglmlist} object.}

\item{type}{Type of output: \code{"brackets"} for loglinear bracket notation
(e.g., \code{"[AB] [C]"}), or \code{"formula"} for R formula notation.
For \code{glm} and \code{glmlist} objects, only \code{"formula"} is meaningful.}

\item{abbrev}{Logical or integer. If \code{TRUE} or a positive integer,
abbreviate factor names to that many characters (default 1 when \code{TRUE}).
Only applies to bracket notation.}

\item{\dots}{Additional arguments passed to \code{loglin2string}
such as \code{sep} and \code{collapse}.}
}
\value{
For \code{get_model()}: a character string with the model formula or bracket notation.

\if{html}{\out{<div class="sourceCode">}}\preformatted{    For `get_models()`: a named character vector with the model formulas or bracket notations.
}\if{html}{\out{</div>}}
}
\description{
\code{get_model()} extracts the model formula or bracket notation from a single
\code{loglm} or \code{glm} object.
}
\details{
\code{get_models()} does the same for each model in a
\code{loglmlist} or \code{glmlist} object.
These are useful for labeling models in summaries and plots.

For \code{loglm} objects created by \code{\link{seq_loglm}}, the bracket
notation is stored in the \code{model.string} component. For other \code{loglm}
objects, it is constructed from the \code{margin} component using
\code{\link{loglin2string}}.

For \code{glm} objects, the formula is extracted using \code{formula()}.

\strong{Model notation}

For \code{loglmlist} objects created by \code{\link{seq_loglm}}, the bracket
notation distinguishes between models fit to marginal sub-tables and
models fit to the full table. Parentheses are used for marginal
sub-tables, e.g., \code{"(Class) (Sex)"}, while square brackets are used
for the full table, e.g., \code{"[Class,Sex,Age] [Survived]"}.

The \code{abbrev} argument can be used to abbreviate factor names
for more compact display, e.g., \code{"[C,S,A] [S]"}.
}
\examples{
data(Titanic)
tit.joint <- seq_loglm(Titanic, type = "joint")

# Single model
get_model(tit.joint[[2]])
get_model(tit.joint[[4]])
get_model(tit.joint[[4]], abbrev = TRUE)
get_model(tit.joint[[4]], type = "formula")

# Model list
get_models(tit.joint)
get_models(tit.joint, type = "formula")

# With abbreviated factor names
get_models(tit.joint, abbrev = TRUE)
get_models(tit.joint, abbrev = 2)

}
\seealso{
\code{\link{glmlist}}, \code{\link{loglmlist}},
\code{\link{loglin2string}}, \code{\link{LRstats}},
\code{\link{seq_mosaic}}

Other glmlist functions:
\code{\link[=Kway]{Kway()}},
\code{\link[=LRstats]{LRstats()}},
\code{\link[=glmlist]{glmlist()}},
\code{\link[=mosaic.glmlist]{mosaic.glmlist()}}

Other loglinear models:
\code{\link[=assoc_graph]{assoc_graph()}},
\code{\link[=glmlist]{glmlist()}},
\code{\link[=joint]{joint()}},
\code{\link[=plot.assoc_graph]{plot.assoc_graph()}},
\code{\link[=seq_loglm]{seq_loglm()}}
}
\concept{glmlist functions}
\concept{loglinear models}
