Fit a Generalized Additive Model

DESCRIPTION:
Returns an object of class "gam" which is a generalized additive fit of the model.

USAGE:
gam(formula, family = gaussian, data = <<see below>>,
    weights = <<see below>>, subset = <<see below>>,
    na.action = na.fail, start = <<see below>>,
    control = gam.control(...), trace = F, model = F,
    x = F, y = T, contrasts = NULL, ...)

REQUIRED ARGUMENTS:
formula:
a formula object, with the response of the left of a ~ operator, and the terms, separated by + operators, on the right. Nonparametric smoothing terms are indicated by s for smoothing splines or lo for loess smooth terms. Additional smoothers can be added by creating the appropriate interface. Interactions with nonparametric smooth terms are not fully supported, but will not produce errors; they will simply produce the usual parametric interaction.

OPTIONAL ARGUMENTS:
family:
a family object, a list of functions and expressions for defining the link and variance functions, initialization, and iterative weights. Families supported are gaussian, binomial, poisson, Gamma, inverse.gaussian and quasi. Functions such as binomial produce a family object, but can be given without the parentheses. Family functions can take arguments, as in binomial(link=probit).
data:
a data frame containing the variables occurring in the formula. If this is missing, the variables should be on the search list.
weights:
vector of the observation weights for the fitting criterion. The length must be the same as the number of observations in the data. By default, an unweighted fit is produced.
subset:
expression saying which subset of the rows of the data should be used in the fit. This can be a logical vector (which is replicated to have length equal to the number of observations), a numeric vector indicating which observation numbers are to be included, or a character vector of the row names to be included. All observations are included by default.
na.action:
a function to filter missing data. This is applied to the model.frame after any subset argument has been used. The default (with na.fail) is to create an error if any missing values are found. A possible alternative is na.omit, which deletes observations that contain one or more missing values.
start:
vector of initial values on the scale of the additive predictor.
control:
a list of iteration and algorithmic constants. See gam.control for their names and default values. These can also be set as arguments to gam itself.
trace:
logical flag: if TRUE, then the status during each iteration of the fitting is reported.
x:
logical flag: if TRUE, then the x matrix is returned as component x.
y:
logical flag: if TRUE, then the response is returned as component y.
contrasts:
list of contrasts to be used for some or all of the factors appearing as variables in the model formula. The names of the list should be the names of the corresponding variables. The elements should either be contrast-type matrices (matrices with as many rows as levels of the factor and with columns linearly independent of each other and of a column of ones), or else they should be functions that compute such contrast matrices.
...:
all the optional arguments to lm can be given including weights, subset and na.action.

VALUE:
an object of class gam is returned, which inherits from both glm and lm. See gam.object for details.

DETAILS:
Components can be extracted using extractor functions predict, fitted, residuals, deviance, formula, and family. The output can be modified using update. It has all the components of a glm object, with a few more.

The response variable must conform with the definition of family, for example factor or binary data if family=binomial is declared.

The model is fit using the local scoring algorithm, which iteratively fits weighted additive models by backfitting. The backfitting algorithm is a Gauss-Seidel method for fitting additive models, by iteratively smoothing partial residuals. The algorithm separates the parametric from the nonparametric part of the fit, and fits the parametric part using weighted linear least squares within the backfitting algorithm.

Although nonparametric smooth terms lo and s can be mixed in a formula, it is faster and less memory intensive to use a single smoothing method for all the smoothing terms in an additive model. In this case the entire local scoring algorithm is performed in Fortran, which, although faster, is not readable or modifiable by the user.


REFERENCES:
Hastie, T. and Tibshirani, R. (1990). Generalized Additive Models. Chapman and Hall, London.

SEE ALSO:
family , formula , gam.control , gam.object , glm , lm , lo , model.frame , plot.gam , preplot.gam , s .

EXAMPLES:
gam(Kyphosis ~ s(Age,4) + Number, family = binomial, data = kyphosis)
gam(ozone^(1/3) ~ lo(radiation) + lo(wind, temperature), data = air)
gam(Kyphosis ~ poly(Age, 2) + s(Start), data = kyphosis,
    subset = Number>5)