expand.model.frame
Add new variables to a model frame
Description
Evaluates a model frame with extra variables and the same data,
subset and na.action arguments.
Usage
expand.model.frame(model, extras, envir = environment(formula(model)), na.expand = FALSE)
Arguments
model |
a fitted model.
|
extras |
a one-side formula or a character vector giving the new variables to be added.
|
envir |
an environment to evaluate the data and the model frame. By default, the environment is the
same as the environment that the specified model uses.
|
na.expand |
a logical value.
- If TRUE, then the missing values in the new variables specified by
the extras argument are ignored
and the returned model.frame contains the same rows as the old
model.frame, with additional columns corresponding to the added variables, which
may contain missing values.
- If FALSE (the default), then the missing values in the new variables are handled by
the function that is specified by the na.action given to the modeling function
that creates the model, so the returned model.frame
could have fewer rows than the model.frame in the model argument.
|
Details
A new formula containing the variables in old model and new variables specified in
extras will be created. The returned model frame is re-evaluated with this new
formula, old data, old subset, old environment and suitable NAs handling(dependent
on na.expand).
Value
returns a model frame object.
See Also
Examples
model <- lm(ozone ~ radiation, data = Sdatasets::air[c(1,11,21,31,111),])
expand.model.frame(model, ~ temperature)
expand.model.frame(model, c("wind", "temperature"))
fakeData <- data.frame(x=log2(1:5), y=3:7, z=1/c(1,NA,3,4,5))
model0 <- glm(y ~ x, family=poisson, data=fakeData, subset=2:5, na.action=na.exclude)
expand.model.frame(model0, ~x*z, na.expand=FALSE) # = default
expand.model.frame(model0, ~x*z, na.expand=TRUE)