Simon N. Wood
href=\
Front end design inspired by the S function of the same name based on the work of Hastie and Tibshirani (1990). Underlying methods owe much to the work of Wahba (e.g. 1990) and Gu (e.g. 2002).
参考文献----------References----------
and marginal likelihood estimation of semiparametric generalized linear models. Journal of the Royal Statistical Society (B) 73(1):3-36
generalized additive models. J. Amer. Statist. Ass. 99:673-686. [Default method for additive case by GCV (but no longer for generalized)]
generalized additive mixed models. Biometrics 62(4):1025-1036 and Hall/CRC Press.
in mixed models. Statistical Computing.
Model Components. Scandinavian Journal of Statistics, 39(1), 53-74.
and Hall.
with Multiple Quadratic Penalties. J.R.Statist.Soc.B 62(2):413-428 [The original mgcv paper, but no longer the default methods.]
the Newton method. SIAM J. Sci. Statist. Comput. 12:383-398
functions in generalized linear models. J. Am. Statist.Ass. 81:96-103
to environmental modelling. Ecological Modelling 157:157-177
参见----------See Also----------
mgcv-package, gamObject, gam.models, smooth.terms, linear.functional.terms, s, te predict.gam, plot.gam, summary.gam, gam.side, gam.selection, gam.control gam.check, linear.functional.terms negbin, magic,vis.gam
mgcv-package,gamObject,gam.models,smooth.terms,linear.functional.terms,s,
tepredict.gam,
实例----------Examples----------
library(mgcv)
set.seed(2) ## simulate some data... [#模拟一些数据...]
dat <- gamSim(1,n=400,dist=\b <- gam(y~s(x0)+s(x1)+s(x2)+s(x3),data=dat) summary(b)
plot(b,pages=1,residuals=TRUE) ## show partial residuals[#显示部分残差] plot(b,pages=1,seWithMean=TRUE) ## `with intercept' CIs[#拦截的证明书]
## run some basic model checks, including checking[#运行一些基本的模型检查,包括检查]
## smoothing basis dimensions...[#平滑基础尺寸...] gam.check(b)
## same fit in two parts .....[#适合两部分......]
G <- gam(y~s(x0)+s(x1)+s(x2)+s(x3),fit=FALSE,data=dat) b <- gam(G=G) print(b)
## change the smoothness selection method to REML[#改变平滑的选择方法,以REML] b0 <- gam(y~s(x0)+s(x1)+s(x2)+s(x3),data=dat,method=\plot(b0,pages=1,scheme=1)
## Would a smooth interaction of x0 and x1 be better?[#将一个流畅的交互X0和X1是更好吗?]
## Use tensor product smooth of x0 and x1, basis [#使用张量积X0和X1的流畅性,基础]
## dimension 49 (see ?te for details, also ?t2).[尺寸49(见TE的详细信息,也T2)。] bt <- gam(y~te(x0,x1,k=7)+s(x2)+s(x3),data=dat, method=\plot(bt,pages=1)
plot(bt,pages=1,scheme=2) ## alternative visualization[#另一种可视化] AIC(b0,bt) ## interaction worse than additive[#互动不如添加剂]
## If it is believed that x0 and x1 are naturally on [#如果可以相信,x0和x1自然]
## the same scale, and should be treated isotropically [#同样的规模,并应被视为各向同性]
## then could try...[#,那么可以尝试...]
bs <- gam(y~s(x0,x1,k=50)+s(x2)+s(x3),data=dat,
method=\plot(bs,pages=1)
AIC(b0,bt,bs) ## additive still better. [#添加剂仍然较好。]
## Now do automatic terms selection as well[#现在做自动的条款的选择,以及] b1 <- gam(y~s(x0)+s(x1)+s(x2)+s(x3),data=dat, method=\plot(b1,pages=1)
## set the smoothing parameter for the first term, estimate rest ...[#设置平滑参数的第一个任期内,估计截断...]
bp <- gam(y~s(x0)+s(x1)+s(x2)+s(x3),sp=c(0.01,-1,-1,-1),data=dat) plot(bp,pages=1,scheme=1) ## alternatively...[#或者...]
bp <- gam(y~s(x0,sp=.01)+s(x1)+s(x2)+s(x3),data=dat)
# set lower bounds on smoothing parameters ....[平滑参数设置下限....] bp<-gam(y~s(x0)+s(x1)+s(x2)+s(x3),
min.sp=c(0.001,0.01,0,10),data=dat) print(b);print(bp)
# same with REML[同REML]
bp<-gam(y~s(x0)+s(x1)+s(x2)+s(x3),
min.sp=c(0.1,0.1,0,10),data=dat,method=\print(b0);print(bp)
## now a GAM with 3df regression spline term & 2 penalized terms[#现在的处罚条款与的3DF回归样条术语和2 GAM]
b0<-gam(y~s(x0,k=4,fx=TRUE,bs=\plot(b0,pages=1)
## now simulate poisson data...[#现在模拟Poisson数据...]
dat <- gamSim(1,n=4000,dist=\
## use \使用“CR”的基础上,以节省时间,4000的数据...]
b2<-gam(y~s(x0,bs=\
s(x3,bs=\plot(b2,pages=1)
## drop x3, but initialize sp's from previous fit, to [#下降X3,但初始化SP,从以前的配合,]
## save more time...[#节省更多的时间。]
b2a<-gam(y~s(x0,bs=\ family=poisson,data=dat,method=\ in.out=list(sp=b2$sp[1:3],scale=1)) par(mfrow=c(2,2)) plot(b2a)
par(mfrow=c(1,1))
## similar example using performance iteration[#类似的例子使用性能迭代] dat <- gamSim(1,n=400,dist=\
b3<-gam(y~s(x0)+s(x1)+s(x2)+s(x3),family=poisson, data=dat,optimizer=\plot(b3,pages=1)
## repeat using GACV as in Wood 2008...[#重复使用GACV的2008年在木...]
b4<-gam(y~s(x0)+s(x1)+s(x2)+s(x3),family=poisson, data=dat,method=\.Cp\plot(b4,pages=1)
## repeat using REML as in Wood 2011...[]
b5<-gam(y~s(x0)+s(x1)+s(x2)+s(x3),family=poisson, data=dat,method=\plot(b5,pages=1)
## a binary example (see later for large dataset version)...[#一个二进制的例子(见后面的大数据集的版本)...]
dat <- gamSim(1,n=400,dist=\
lr.fit <- gam(y~s(x0)+s(x1)+s(x2)+s(x3),family=binomial, data=dat,method=\
## plot model components with truth overlaid in red[#图模型组件覆盖在红色与真理] op <- par(mfrow=c(2,2))
fn <- c(\for (k in 1:4) {
plot(lr.fit,residuals=TRUE,select=k)
ff <- dat[[fn[k]]];xx <- dat[[xn[k]]]
ind <- sort.int(xx,index.return=TRUE)$ix lines(xx[ind],(ff-mean(ff))[ind]*.33,col=2) }
par(op) anova(lr.fit)
lr.fit1 <- gam(y~s(x0)+s(x1)+s(x2),family=binomial, data=dat,method=\
lr.fit2 <- gam(y~s(x1)+s(x2),family=binomial, data=dat,method=\AIC(lr.fit,lr.fit1,lr.fit2)
## A Gamma example, by modify `gamSim' output...[#的伽玛例如,通过的修改gamSim“输出...]
dat <- gamSim(1,n=400,dist=\
dat$f <- dat$f/4 ## true linear predictor [#真正的线性预测]
Ey <- exp(dat$f);scale <- .5 ## mean and GLM scale parameter[#的意思,GLM尺度参数]
## Note that `shape' and `scale' in `rgamma' are almost[#需要注意的是形和规模在rgamma是几乎]
## opposite terminology to that used with GLM/GAM...[#相对所用的术语,以与GLM / GAM ...]
dat$y <- rgamma(Ey*0,shape=1/scale,scale=Ey*scale)
bg <- gam(y~ s(x0)+ s(x1)+s(x2)+s(x3),family=Gamma(link=log), data=dat,method=\plot(bg,pages=1,scheme=1)
## For inverse Gaussian, see ?rig[#逆高斯,看到了吗?钻机]
## now a 2D smoothing example...[#现在的2D平滑的例子...]
eg <- gamSim(2,n=500,scale=.1) attach(eg)
op <- par(mfrow=c(2,2),mar=c(4,4,1,1))
contour(truth$x,truth$z,truth$f) ## contour truth[#轮廓真相] b4 <- gam(y~s(x,z),data=data) ## fit model[#拟合模型] fit1 <- matrix(predict.gam(b4,pr,se=FALSE),40,40)
contour(truth$x,truth$z,fit1) ## contour fit[#轮廓适合]
persp(truth$x,truth$z,truth$f) ## persp truth[#persp真相] vis.gam(b4) ## persp fit[#persp适合] detach(eg)