\Header{expand.model.frame}{Add new variables to a model frame}
\keyword{manip}{expand.model.frame}
\keyword{regression}{expand.model.frame}
\begin{Description}\relax
Evaluates new variables as if they had been part of the formula of the
specified model.  This ensures that the same \code{na.action} and
\code{subset} arguments are applied and allows e.g. \code{x} to be
recovered for a model using \code{sin(x)} as a predictor.\end{Description}
\begin{Usage}
\begin{verbatim}
expand.model.frame(model, extras, enclos = sys.frame(sys.parent()),
                   na.expand = FALSE)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{model}] A fitted model
\item[\code{extras}] One-sided formula or vector of character strings
describing new variables to be added
\item[\code{enclos}] An environment to evaluate things in
\item[\code{na.expand}] See below
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
If \code{na.expand=FALSE} then \code{NA} values in the extra variables
will be passed to the \code{na.action} function used in
\code{model}. This may result in a shorter data frame (with
\code{\Link{na.omit}}) or an error (with \code{\Link{na.fail}}).  If
\code{na.expand=TRUE} the returned data frame will have precisely the
same rows as \code{model.frame(model)}, but the columns corresponding to
the extra variables may contain \code{NA}.\end{Details}
\begin{Value}
A data frame.\end{Value}
\begin{SeeAlso}\relax
\code{\Link{model.frame}},\code{\Link{predict}}\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
data(trees)
model <- lm(log(Volume) ~ log(Girth) + log(Height), data=trees)
expand.model.frame(model, ~ Girth)
dd <- data.frame(x=1:5, y=rnorm(5), z=c(1,2,NA,4,5))
model <- glm(y ~ x, data=dd, subset=1:4, na.action=na.omit)
expand.model.frame(model, "z", na.expand=FALSE)
expand.model.frame(model, "z", na.expand=TRUE)
\end{ExampleCode}
\end{Examples}

