% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/find_terms.R
\name{find_terms}
\alias{find_terms}
\alias{find_terms.default}
\title{Find all model terms}
\usage{
find_terms(x, ...)

\method{find_terms}{default}(x, flatten = FALSE, as_term_labels = FALSE, verbose = TRUE, ...)
}
\arguments{
\item{x}{A fitted model.}

\item{...}{Currently not used.}

\item{flatten}{Logical, if \code{TRUE}, the values are returned as character
vector, not as list. Duplicated values are removed.}

\item{as_term_labels}{Logical, if \code{TRUE}, extracts model formula and tries to
access the \code{"term.labels"} attribute. This should better mimic the \code{terms()}
behaviour even for those models that do not have such a method, but may be
insufficient, e.g. for mixed models.}

\item{verbose}{Toggle warnings.}
}
\value{
A list with (depending on the model) following elements (character
vectors):
\itemize{
\item \code{response}, the name of the response variable
\item \code{conditional}, the names of the predictor variables from the \emph{conditional}
model (as opposed to the zero-inflated part of a model)
\item \code{random}, the names of the random effects (grouping factors)
\item \code{zero_inflated}, the names of the predictor variables from the \emph{zero-inflated} part of the model
\item \code{zero_inflated_random}, the names of the random effects (grouping factors)
\item \code{dispersion}, the name of the dispersion terms
\item \code{instruments}, the names of instrumental variables
}

Returns \code{NULL} if no terms could be found (for instance, due to
problems in accessing the formula).
}
\description{
Returns a list with the names of all terms, including response
value and random effects, "as is". This means, on-the-fly tranformations
or arithmetic expressions like \code{log()}, \code{I()}, \code{as.factor()} etc. are
preserved.
}
\note{
The difference to \code{\link[=find_variables]{find_variables()}} is that \code{find_terms()}
may return a variable multiple times in case of multiple transformations
(see examples below), while \code{find_variables()} returns each variable
name only once.
}
\section{Parameters, Variables, Predictors and Terms}{

There are four functions that return information about the variables in a
model: \code{find_predictors()}, \code{find_variables()}, \code{find_terms()} and
\code{find_parameters()}. There are some differences between those functions,
which are explained using following model. Note that some, but not all of
those functions return information about the \emph{dependent} and \emph{independent}
variables. In this example, we only show the differences for the independent
variables.

\if{html}{\out{<div class="sourceCode">}}\preformatted{model <- lm(mpg ~ factor(gear), data = mtcars)
}\if{html}{\out{</div>}}
\itemize{
\item \code{find_terms(model)} returns the model terms, i.e. how the variables were
used in the model, e.g. applying transformations like \code{factor()}, \code{poly()}
etc. \code{find_terms()} may return a variable name multiple times in case of
multiple transformations. The return value would be \code{"factor(gear)"}.
\item \code{find_parameters(model)} returns the names of the model parameters
(coefficients). The return value would be \code{"(Intercept)"}, \code{"factor(gear)4"}
and \code{"factor(gear)5"}.
\item \code{find_variables()} returns the original variable names. \code{find_variables()}
returns each variable name only once. The return value would be \code{"gear"}.
\item \code{find_predictors()} is comparable to \code{find_variables()} and also returns
the original variable names, but excluded the \emph{dependent} (response)
variables. The return value would be \code{"gear"}.
}
}

\examples{
\dontshow{if (require("lme4", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf}
data(sleepstudy, package = "lme4")
m <- suppressWarnings(lme4::lmer(
  log(Reaction) ~ Days + I(Days^2) + (1 + Days + exp(Days) | Subject),
  data = sleepstudy
))

find_terms(m)

# sometimes, it is necessary to retrieve terms from "term.labels" attribute
m <- lm(mpg ~ hp * (am + cyl), data = mtcars)
find_terms(m, as_term_labels = TRUE)
\dontshow{\}) # examplesIf}
}
