update
Update a Fitted Model Object
Description
Creates a new model or object, using the same call used for an earlier
model or object, except for some changes.
Usage
update(object, ...)
## Default S3 method:
update(object, formula., ..., evaluate = TRUE)
## S3 method for class 'formula':
update(old, new, ...)
getCall(x, ...)
## Default S3 method:
getCall(x, ...)
Arguments
object, x |
any object with a component or S4 slot named "call", typically
the result of fitting a model.
|
formula., old, new |
a modeling formula, such as y ~ a + b.
A single dot . on either side of the ~ of formula. or new
gets replaced by the left or right side of the formula in object or old.
The dot on the left can be omitted.
By default, it refits object using the same formula as in object.
|
... |
any other arguments that are appropriate for the particular call.
These must all be named, and may be abbreviated, in the same manner they
could be as arguments to the fitting function itself.
Arguments in the previous fit; that is, in
object$call, can be removed by putting nothing on the right side of the =.
For example, the argument x=, in a call to update() causes the x argument, if present in object$call, to be removed.
|
evaluate |
if TRUE (the default), the new call is evaluated; otherwise, the call is returned as an unevaluated expression.
|
Details
- update is a generic function.
Do methods("update") to see a list of
currently-defined methods.
- Not all methods support the
evaluate and
class arguments.
- update works by extracting
the call contained
in the old object, modifying it, and evaluating the modified call.
update does
not use any part of the old object except for its call
(as a general rule; some methods may differ).
So, for example,
if you have added attributes to the object after it was created,
they will not be included in the new result.
Also, the old object is not changed, unless you overwrite it
with the new result.
- update does not support objects whose
calls contain abbreviations for argument names.
Typically object is created by a
function that calls either sys.call() or
match.call() to create the call;
the latter is preferable for update
because it expands abbreviated argument names.
- getCall is also an S3 generic function
so one may define methods for classes which do
not keep the call information in a component
or S4 slot named "call".
Value
update |
returns either a new updated object, or it returns an unevaluated expression for creating such an object.
|
getCall |
returns the list component or S4 slot, but not the attribute, named "call".
|
References
Chambers, J. M. and Hastie, T .J. (Eds.) 1992. Statistical Models in S. Pacific Grove, CA.: Wadsworth & Brooks/Cole. Chapter 4.
See Also
Examples
fit <- lm(Fuel ~ Weight + Type, data = Sdatasets::fuel.frame)
# Refit, unchanged
update(fit)
# Refit, adding term
update(fit, ~ . + Disp.) # add displacement to the model
# Transform response to log scale; drop intercept
update(fit, log(.) ~ . -1)
# Use all the 2nd order interactions of original fit
update(fit, ~ .^2)
# Supply a subset
update(fit, subset= (Type != "Van")) # look only at cars, exclude vans
# Remove an argument, prevent evaluation (would fail)
update(fit, data =, evaluate = FALSE)
getCall(fit)