gam(formula,data,weights,family,scale)
gam
was called is
searched for the variables specified in the formula."gam"
which has the following elements:xp[i,]
are the locations for
the ith smooth.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
.
Details are
given in Wood (2000).Wood (2000) Modelling and Smoothing Parameter Estimation with Multiple Quadratic Penalties. JRSSB 62(2):413-428
predict.gam
plot.gam
library(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
y <- 2 * sin(pi * x0)
y <- y + exp(2 * x1) - 3.75887
y <- y + 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 <- y + e
b<-gam(y~s(x0)+s(x1)+s(x2)+s(x3))
plot(b)
# now fit GAM with 3df regression spline term and two penalized terms
b<-gam(y~s(x0,4|f)+s(x1)+s(x2,15))
Run the code above in your browser using DataLab