gam.s: Specify a Smoothing Spline Fit in a GAM Formula

gam.sR Documentation

Specify a Smoothing Spline Fit in a GAM Formula

Description

A symbolic wrapper to indicate a smooth term in a formala argument to gam

Usage

gam.s(x, y, w = rep(1, length(x)), df = 4, spar = 1, xeval)

s(x, df = 4, spar = 1)

Arguments

x

the univariate predictor, or expression, that evaluates to a numeric vector.

y

a response variable passed to gam.s during backfitting

w

weights

df

the target equivalent degrees of freedom, used as a smoothing parameter. The real smoothing parameter (spar below) is found such that df=tr(S)-1, where S is the implicit smoother matrix. Values for df should be greater than 1, with df=1 implying a linear fit. If both df and spar are supplied, the former takes precedence. Note that df is not necessarily an integer.

spar

can be used as smoothing parameter, with values typically in (0,1]. See smooth.spline for more details.

xeval

If this argument is present, then gam.s produces a prediction at xeval.

Value

s returns the vector x, endowed with a number of attributes. The vector itself is used in the construction of the model matrix, while the attributes are needed for the backfitting algorithms general.wam (weighted additive model) or s.wam. Since smoothing splines reproduces linear fits, the linear part will be efficiently computed with the other parametric linear parts of the model.

Note that s itself does no smoothing; it simply sets things up for gam.

One important attribute is named call. For example, s(x) has a call component gam.s(data[["s(x)"]], z, w, spar = 1, df = 4). This is an expression that gets evaluated repeatedly in general.wam (the backfitting algorithm).

gam.s returns an object with components

residuals

The residuals from the smooth fit. Note that the smoother removes the parametric part of the fit (using a linear fit in x), so these residual represent the nonlinear part of the fit.

nl.df

the nonlinear degrees of freedom

var

the pointwise variance for the nonlinear fit

When gam.s is evaluated with an xeval argument, it returns a vector of predictions.

Author(s)

Written by Trevor Hastie, following closely the design in the "Generalized Additive Models" chapter (Hastie, 1992) in Chambers and Hastie (1992).

References

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.

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

Cantoni, E. and hastie, T. (2002) Degrees-of-freedom tests for smoothing splines, Biometrika 89(2), 251-263

See Also

lo, smooth.spline, bs, ns, poly

Examples


     # fit Start using a smoothing spline with 4 df.
     y ~ Age + s(Start, 4)
     # fit log(Start) using a smoothing spline with 5 df.
     y ~ Age + s(log(Start), df=5)
 

gam documentation built on Sept. 13, 2024, 1:06 a.m.