Rev 27688 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
\name{model.frame}\alias{model.frame}\alias{model.frame.default}\alias{model.frame.lm}\alias{model.frame.glm}\alias{model.frame.aovlist}\title{Extracting the ``Environment'' of a Model Formula}\usage{model.frame(formula, \dots)\method{model.frame}{default}(formula, data = NULL,subset = NULL, na.action = na.fail,drop.unused.levels = FALSE, xlev = NULL, \dots)\method{model.frame}{aovlist}(formula, data = NULL, \dots)\method{model.frame}{glm}(formula, \dots)\method{model.frame}{lm}(formula, \dots)}\arguments{\item{formula}{a model \code{\link{formula}} or \code{\link{terms}}object or an \R object.}\item{data}{\code{data.frame}, list, \code{environment} or objectcoercible to \code{data.frame} containing the variables in\code{formula}. Neither a matrix nor an array will be accepted.}\item{subset}{a specification of the rows to be used: defaults to allrows. This can be any valid indexing vector (see\code{\link{[.data.frame}}) for the rows of \code{data} or if that is notsupplied, a data frame made up of the variables used in \code{formula}.}\item{na.action}{how \code{NA}s are treated. The default is first,any \code{na.action} attribute of \code{data}, seconda \code{na.action} setting of \code{\link{options}}, and third\code{\link{na.fail}} if that is unset. The \dQuote{factory-fresh}default is \code{\link{na.omit}}.}\item{drop.unused.levels}{should factors have unused levels dropped?Defaults to \code{FALSE}.}\item{xlev}{a named list of character vectors giving the full set of levelsto be assumed for each factor.}\item{\dots}{further arguments such as \code{data}, \code{na.action},\code{subset}. Any additional arguments such as \code{offset} and\code{weights} which reach the default method are used to createfurther columns in the model frame, with parenthesised names such as\code{"(offset)"}.}}\description{\code{model.frame} (a generic function) and its methods return a\code{\link{data.frame}} with the variables needed to use\code{formula} and any \code{\dots} arguments.}\details{Exactly what happens depends on the class and attributes of the object\code{formula}. If this is an object of fitted-model class such as\code{"lm"}, the method will either returned the saved model frameused when fitting the model (if any, often selected by argument\code{model = TRUE}) or pass the call used when fitting on to thedefault method. The default method itself can cope with ratherstandard model objects such as those of classes\code{"\link[MASS]{lqs}"} and \code{"\link[ppr]{ppr}"} if no otherarguments are supplied.The rest of this section applies only to the default method.If either \code{formula} or \code{data} is already a model frame (adata frame with a \code{"terms"} attribute and the other is missing,the model frame is returned. Unless \code{formula} is a terms object,\code{terms} is called on it. (If you wish to use the\code{keep.order} argument of \code{terms.formula}, pass a termsobject rather than a formula.)All the variables in \code{formula}, \code{subset} and in \code{\dots}are looked for first in \code{data} and then in the environment of\code{formula} (see the help for \code{\link{formula}()} for furtherdetails) and collected into a data frame. Then the \code{subset}expression is evaluated, and it is is used as a row index to the dataframe. Then the \code{na.action} function is applied to the data frame(and may well add attributes). The levels of any factors in the dataframe are adjusted according to the \code{drop.unused.levels} and\code{xlev} arguments.}\value{A \code{\link{data.frame}} containing the variables used in\code{formula} plus those specified \code{\dots}.}\seealso{\code{\link{model.matrix}} for the \dQuote{design matrix},\code{\link{formula}} for formulas and\code{\link{expand.model.frame}} for model.frame manipulation.}\references{Chambers, J. M. (1992)\emph{Data for models.}Chapter 3 of \emph{Statistical Models in S}eds J. M. Chambers and T. J. Hastie, Wadsworth \& Brooks/Cole.}\examples{data(cars)data.class(model.frame(dist ~ speed, data = cars))}\keyword{models}