na.gam.replace: Missing Data Filter for GAMs

Description Usage Arguments Value Author(s) References See Also Examples


A method for dealing with missing values, friendly to GAM models.





a model or data frame


a model or data frame is returned, with the missing observations (NAs) replaced. The following rules are used. A factor with missing data is replaced by a new factor with one more level, labelled "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 Hastie (1992) for more details.


Trevor Hastie


Hastie, T. J. (1992) Generalized additive models. Chapter 7 of Statistical Models in S eds J. M. Chambers and T. J. Hastie, Wadsworth \& Brooks/Cole.

See Also, na.omit, gam


gam(Ozone^(1/3) ~ lo(Solar.R) + lo(Wind, Temp), data=airquality, na=na.gam.replace)

Example output

Loading required package: splines
Loading required package: foreach
Loaded gam 1.16

gam(formula = Ozone^(1/3) ~ lo(Solar.R) + lo(Wind, Temp), data = airquality, 
    na.action = na.gam.replace)

Degrees of Freedom: 115 total; 102.6679 Residual
Residual Deviance: 20.05229 
Warning message:
In na.action(mf) :
  37 observations omitted due to missing values in the response

gam documentation built on July 8, 2020, 7:24 p.m.

Related to na.gam.replace in gam...