A Missing Data Filter

DESCRIPTION:
Replaces NAs in a numeric vector with the mean of non-missing entries.

USAGE:
na.gam.replace(frame)

REQUIRED ARGUMENTS:
frame:
a model or data frame

VALUE:
a model or data frame is returned, with the missing observations (NAs) replaced.

DETAILS:
The following rules are used. A factor with missing data is replaced by a new factor with one more level, labeled "NA", which records the missing data. Ordered factors are treated similarly, except the result is an unordered factor. A missing numeric vector has its missing entires replaced by the mean of the non-missing entries. Similarly, a matrix with missing entries has each missing entry replace by the mean of its column. If frame is a model frame, the response variable can be identified, as can the weights (if present). Any rows for which the response or weight is missing are removed entirely from the model frame.

The word "gam" in the name is relevant, because gam makes special use of this filter. All columns of a model frame that were created by a call to lo or s have an attribute names "NAs" if NAs are present in their columns. Despite the replacement by means, these attributes remain on the object, and gam takes appropriate action when smoothing against these columns. See section 7.3.2 in Statistical Models in S for more details.


SEE ALSO:
gam , na.fail , na.omit , na.tree.replace .

EXAMPLES:
gam(pick ~ s(income) + size, family = binomial,
  data = market.frame, na.action = na.gam.replace)
# fit an additive model in the presence of missing data

replaced.data <- na.gam.replace(market.frame) attach(replaced.data)