如何从 mgcv::gam.check 中保存 edf 并跳过绘图
How to save edf from mgcv::gam.check and skip the plots
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
我想将诊断的输出保存到一个列表(或者只是 table 到一个数据框) 并且 不输出任何图形。
我考虑过的事情:
下面的代码 returns 一个空对象。
x<-gam.check(b,pch=19,cex=.3)
查看了 gam.check 的代码,看来我想要 'get' 来自
的结果
kchck <- k.check(b, 子样本 = k.sample, n.rep = k.rep)
不幸的是,运行 上面的代码行直接产生了一个'找不到函数"k.check"。
我可以使用接收器将输出保存到控制台,但这不会关闭绘图。
Gavin Simpson provided a great answer for extracting plots here 但我没有看到任何有助于解决我的问题的信息。
user20650 上面评论中的答案很准确...
For your option two, use the package name... ie mgcv:::k.check so then
can use f <- function(b, k.sample = 5000, k.rep = 200)
printCoefmat(mgcv:::k.check(b, subsample = k.sample, n.rep = k.rep),
digits = 3)
...出于我的目的,我放弃了 printCoefmat
f <- function(b, k.sample = 5000, k.rep = 200) {
mgcv:::k.check(b, subsample = k.sample, n.rep = k.rep)
}
(basis <- f(b))
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
我想将诊断的输出保存到一个列表(或者只是 table 到一个数据框) 并且 不输出任何图形。
我考虑过的事情:
下面的代码 returns 一个空对象。
x<-gam.check(b,pch=19,cex=.3)
查看了 gam.check 的代码,看来我想要 'get' 来自
的结果kchck <- k.check(b, 子样本 = k.sample, n.rep = k.rep)
不幸的是,运行 上面的代码行直接产生了一个'找不到函数"k.check"。
我可以使用接收器将输出保存到控制台,但这不会关闭绘图。
Gavin Simpson provided a great answer for extracting plots here 但我没有看到任何有助于解决我的问题的信息。
user20650 上面评论中的答案很准确...
For your option two, use the package name... ie mgcv:::k.check so then can use f <- function(b, k.sample = 5000, k.rep = 200) printCoefmat(mgcv:::k.check(b, subsample = k.sample, n.rep = k.rep), digits = 3)
...出于我的目的,我放弃了 printCoefmat
f <- function(b, k.sample = 5000, k.rep = 200) {
mgcv:::k.check(b, subsample = k.sample, n.rep = k.rep)
}
(basis <- f(b))