Update a Fitted Model Object

DESCRIPTION:

Create a new model or object, using the same call used for an earlier model or object, except for some changes.

USAGE:

update(object, ...)
update(object, formula, ..., evaluate=T, class)

REQUIRED ARGUMENTS:

object
any object with a component or attribute named call, which is the expression used to create itself (with no abbreviations for argument names).

OPTIONAL ARGUMENTS:

formula
a modeling formula, such as y ~ a + b. A single dot . on either side of the ~ gets replaced by the left or right side of the formula in object. 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.
class
the fitting class to be used for the new object; that is, the basic fitting function, such as lm(), aov(), glm(), etc. This argument allows the model to be switched from one kind to another, assuming the formula and other arguments make sense for the new model. Although suggestive, class is a slight misnomer since the object may already inherit from this new class.

VALUE:

either a new updated object, or else an unevaluated expression for creating such an object.

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.

SEE ALSO:

, , , .

EXAMPLES:

fit <- lm(Fuel ~ Weight + Disp., data = fuel.frame)

# refit, unchanged
update(fit)

# refit, adding term
update(fit, ~ . + Type)

# 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=Weight > 2600)

# Remove an argument, prevent evaluation (would fail)
update(fit, data =, evaluate=F)