naresid(omit, ...) nafitted(omit, ...) napredict(omit, ...) naresid.default(omit, x) nafitted.default(omit, x) napredict.default(omit, x) naresid.exclude(omit, x) nafitted.exclude(omit, x) napredict.exclude(omit, x)
na.action
function such as
na.exclude
. Typically
this will be a component of a model object for which an
na.action
was
specified.
na.action
.
na.action
information.
Currently the only method available is for
na.exclude
. In this
case
na.exclude
returns a data frame with rows containing missing values
removed and the numbers of these rows stored in an
na.action
attribute of
the data frame. The
naresid
function then takes this attribute and the
residuals for the subset data frame, and uses the information on what rows
were removed to return a vector of the same length as the original data. That
is, this function pads with NA's to return a vector of residuals corresponding
to the original data.
Note that for
na.action
functions for which no
naresid
method has been
written the generic
naresid.default
is called. This merely returns the
specified
x
unmodified.
In order for a model to use this system, the modeling function must take
the
na.action
information produced by
model.frame
and place it on
the model object. The following code from
lm
does this:
attr(fit, "na.message") <- attr(m, "na.message")
if(!is.null(attr(m, "na.action")))
fit$na.action <- attr(m, "na.action")
In order for a function such as
residuals.lm
to return the modified
residuals, it must call
naresid
before returning its result. The
convention is to use:
if(is.null(object$na.action))
return(r)
else return(naresid(object$na.action, r))
where
object
is the fitted model and
r
is the residuals for the subset
of data used in the model.
Theoretically, users could write their own function
na.myway
with
corresponding functions
naresid.myway
,
nafitted.myway
, and
napredict.myway
. The developer can expect
naresid
and
nafitted
to be applied to the results of
residuals
and
fitted
. The function
napredict
is currently only applied to the results of
predict
when no
new data is specified. Note that for
na.exclude
all three of these
functions do the same thing. The separate functions for
naresid
,
nafitted
, and
napredict
are available to support more general functionality
than is currently implemented.
if(is.null(object$na.action)) return(r) else return(naresid(object$na.action, r))