naresid
Adjust for Missing Values

Description

Use missing value information to adjust residuals and predictions.

Usage

naresid(omit, x, ...) 
## Default S3 method:
naresid(omit, x, ...) 
## S3 method for class 'exclude':
naresid(omit, x, ...) 
## S3 method for class 'NULL':
naresid(omit, x, ...) 
napredict(omit, x, ...) 
## Default S3 method:
napredict(omit, x, ...) 
## S3 method for class 'exclude':
napredict(omit, x, ...)
## S3 method for class 'NULL':
napredict(omit, x, ...)

Arguments

omit an object produced by an na.action function such as na.exclude. Typically this is the "na.action" component of a model object for which an na.action is specified.
x a vector or matrix to adjust based upon the missing value information. Typically this is the residuals, fitted values, or predictions for the subset of data left after removing rows based on the na.action.
... additional arguments to be passed to or from future methods.

Details

Currently the only method that does anything 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. Then the naresid function takes this attribute and the residuals for the subset data frame and uses the information on the removed rows to return a vector of the same length as the original data. That is, this function pads with NAs 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 just returns the specified x unmodified. 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 demonstrates this:
if(!is.null(attr(m, "na.action"))) fit$na.action <- attr(m, "na.action")
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:
resids <- naresid(object$na.action, rawResids)
where object is the fitted model and rawResids is the residuals for the subset of data used in the model.
An ambitious user could write his own function na.myway with corresponding functions naresid.myway and napredict.myway. The developer can expect naresid to be applied to the results of residuals. The function napredict is currently applied only to the results of predict when no new data is specified.
NOTE: For na.exclude, both of these functions do the same thing. The separate functions for naresid and napredict are available to support more general functionality than is currently implemented.
Value
returns a vector or matrix (with the same number of columns as the input) adjusted based upon the na.action information.
See Also
na.exclude, lm, model.frame
Examples
d <- data.frame(x=c(1,2,NA,4), y=c(11,NA,13,14))
dex <- na.exclude(d)
naresid(attr(dex, "na.action"), dex$y - dex$x)
Package stats version 6.1.1-7
Package Index