gam(formula,family=gaussian(),data=list(),weights=NULL,control=gam.control,scale=0)y ~ . is not allowed).
Smooth terms are specified by expressions of the form:
gam was called is
searched for the variables specified in the formula.gam.control, with three user controllable elements:
maxit controls maximum iterations, convergence tolerance is controlled by epsilon
and the third item is trscale "gam" which has the following elements:xp[i,] are the locations for
the ith smooth.call object containing the call to gam() that produced
this gam object (useful for constructing model frames).You must have more unique combinations of covariates than the model has total parameters. (Total parameters is sum of knots plus sum of non-spline terms less the number of spline terms).
Automatic smoothing parameter selection is not likely to work well when fitting models to very few response data.
x then
there would be a knot at every 10th (ordered) x value. The
use of penalized regression splines turns the gam fitting problem
into a penalized glm fitting problem, which can be fitted using a
slight modification of glm.fit : gam.fit. The penalized
glm
approach also allows smoothing parameters for all smooth terms to
be selected simultaneously by GCV or UBRE. This is achieved as
part of fitting by calling mgcv within gam.fit.
The parameterization used represents the spline in terms of its
values at the knots. Connection of these values at neighbouring knots
by sections of
cubic polynomial constrainted to join at the knots so as to be
continuous up to and including second derivative yields a natural cubic
spline through the values at the knots (given two extra
conditions specifying
that the second derivative of the curve should be zero at the two end
knots). Other parameterizations, such as b-splines or the basis that
arises naturally from r.k.h.s. representation of the spline smoothing
problem are equivalent, but the basis used here has the advantage that
the parameters of the each spline term are easily interpretable.
Details of the GCV/UBRE minimization method are given in Wood (2000).Wood (2000) Modelling and Smoothing Parameter Estimation with Multiple Quadratic Penalties. JRSSB 62(2):413-428
predict.gam plot.gamlibrary(mgcv)
n<-200
sig2<-4
x0 <- runif(n, 0, 1)
x1 <- runif(n, 0, 1)
x2 <- runif(n, 0, 1)
x3 <- runif(n, 0, 1)
pi <- asin(1) * 2
f <- 2 * sin(pi * x0)
f <- f + exp(2 * x1) - 3.75887
f <- f + 0.2 * x2^11 * (10 * (1 - x2))^6 + 10 * (10 * x2)^3 * (1 - x2)^10 - 1.396
e <- rnorm(n, 0, sqrt(abs(sig2)))
y <- f + e
b<-gam(y~s(x0)+s(x1)+s(x2)+s(x3))
plot(b,pages=1)
# now fit GAM with 3df regression spline term and two penalized terms
b1<-gam(y~s(x0,4|f)+s(x1)+s(x2,15))
plot(b1,pages=1)
# now simulate poisson data
g<-exp(f/5)
for (i in 1:length(f)) y[i]<-rpois(1,f[i])
b2<-gam(y~s(x0)+s(x1)+s(x2)+s(x3),family=poisson)
plot(b2,pages=1)Run the code above in your browser using DataLab