要获得结,您可以提取边缘平滑项的xp 分量(注意它是小写的xp,因为在平滑的顶层有一个XP,这是别的东西)。
这是一个例子
library('mgcv')
## simulate some data
set.seed(1729)
df <- gamSim(2) # this is a bivariate example
## fit the model
mod <- gam(y ~ ti(x, bs = 'cr', k = 5) +
ti(z, bs = 'cr', k = 5) +
ti(x, z, bs = rep('cr', 2), k = 5),
data = df$data, method = 'REML')
## extract the 3rd smooth
sm <- mod[['smooth']][[3]]
边缘基在sm$margin,它只是两个平滑对象的列表:
r$> str(sm$margin, max = 1)
List of 2
$ :List of 21
..- attr(*, "class")= chr [1:2] "cr.smooth" "mgcv.smooth"
..- attr(*, "qrc")=List of 4
.. ..- attr(*, "class")= chr "qr"
..- attr(*, "nCons")= int 1
$ :List of 21
..- attr(*, "class")= chr [1:2] "cr.smooth" "mgcv.smooth"
..- attr(*, "qrc")=List of 4
.. ..- attr(*, "class")= chr "qr"
..- attr(*, "nCons")= int 1
每个都有一个xp 组件:
sm_x <- sm$margin[[1]]
sm_z <- sm$margin[[2]]
因此x 的边缘 CRS 的结是:
r$> sm_x$xp
0% 25% 50% 75% 100%
0.0005697084 0.2477067126 0.4704501621 0.7121602102 0.9960833385
对于z 是
r$> sm_z$xp
0% 25% 50% 75% 100%
0.007381999 0.244705125 0.488819070 0.717802322 0.991505836
为什么是这些值?它们位于观察到的协变量值的五分位数:
r$> with(df$data, quantile(x, probs = seq(0, 1, length = 5)))
0% 25% 50% 75% 100%
0.0005697084 0.2477067126 0.4704501621 0.7121602102 0.9960833385
r$> with(df$data, quantile(z, probs = seq(0, 1, length = 5)))
0% 25% 50% 75% 100%
0.007381999 0.244705125 0.488819070 0.717802322 0.991505836
mgcv 是如何为 CRS 基础放置节点的。可以使用place.knots()恢复确切位置:
r$> with(df$data, place.knots(x, 5))
[1] 0.0005697084 0.2477067126 0.4704501621 0.7121602102 0.9960833385
r$> with(df$data, place.knots(z, 5))
[1] 0.007381999 0.244705125 0.488819070 0.717802322 0.991505836
但是从边缘光滑的物体上拉出结更安全,因为用户总是可以通过knots 参数指定结到gam()。