下面的脚本中的gam.check将诊断信息输出到控制台(以及绘图):
library(mgcv)
set.seed(0)
dat <- gamSim(1,n=200)
b<-gam(y~s(x0)+s(x1)+s(x2)+s(x3),data=dat)
gam.check(b,pch=19,cex=.3)
以上代码中的gam.check语句输出到控制台的输出如下:
Method: GCV Optimizer: magic
Smoothing parameter selection converged after 8 iterations.
The RMS GCV score gradient at convergence was 0.00001072609 .
The Hessian was positive definite.
Model rank = 37 / 37
Basis dimension (k) checking results. Low p-value (k-index<1) may
indicate that k is too low, especially if edf is close to k'.
k' edf k-index p-value
s(x0) 9.000 2.318 0.996 0.44
s(x1) 9.000 2.306 0.969 0.32
s(x2) 9.000 7.655 0.961 0.24
s(x3) 9.000 1.233 1.037 0.66
我希望将诊断输出保存到列表(或仅将表保存到数据帧),和不输出任何图形。
我考虑过的事情:
发布于 2017-02-04 11:40:07
user20650在上述评论中的回答是……
在你的第二个选项中,使用包名..。ie mgcv:::k.check因此可以使用f <-函数(b,k.sample = 5000,k.rep = 200) printCoefmat(mgcv:::k.check(b,子样本= k.sample,n.rep = k.rep),数字= 3)
...for我的目的我放弃了printCoefmat
f <- function(b, k.sample = 5000, k.rep = 200) {
mgcv:::k.check(b, subsample = k.sample, n.rep = k.rep)
}
(basis <- f(b))
https://stackoverflow.com/questions/42042822
复制相似问题