如何从张量积交互(mgcv bam)中提取节点的位置?

huangapple go评论59阅读模式
英文:

How to extract locations of knots from a tensor product interaction (mgcv bam)?

问题

以下是您要翻译的内容:

"Let's consider the following data, adapted from here and provided as an example:

library(mgcViz)

set.seed(123)
n <- 10e4
dat <- data.frame("x1" = rnorm(n), "x2" = rnorm(n), "x3" = rnorm(n))
dat$y <- with(dat, sin(x1) + 0.5x2^2 + 0.2x3 + pmax(x2, 0.2) * rnorm(n))
b <- bam(y ~ te(x1, x2, k=c(6,9), bs=c("cr","cr")), data = dat, method = "fREML", discrete = TRUE)
b <- getViz(b)
plot(sm(b, 1)) + l_fitRaster() + l_fitContour() + l_points()

如何从张量积交互(mgcv bam)中提取节点的位置?

Question:
Is there a way to extract both x1 and x2 locations of knots from te() interaction?

英文:

Let's consider the following data, adapted from here and provided as example:

library(mgcViz)  

set.seed(123)
n  &lt;- 10e4
dat &lt;- data.frame(&quot;x1&quot; = rnorm(n), &quot;x2&quot; = rnorm(n), &quot;x3&quot; = rnorm(n))
dat$y &lt;- with(dat, sin(x1) + 0.5*x2^2 + 0.2*x3 + pmax(x2, 0.2) * rnorm(n))
b &lt;- bam(y ~ te(x1, x2, k=c(6,9), bs=c(&quot;cr&quot;,&quot;cr&quot;)), data = dat, method = &quot;fREML&quot;, discrete = TRUE)
b &lt;- getViz(b)
plot(sm(b, 1)) + l_fitRaster() + l_fitContour() + l_points()  

如何从张量积交互(mgcv bam)中提取节点的位置?

Question:
Is there a way to extract both x1 and x2 locations of knots from te() interaction?

答案1

得分: 0

这可以按照这里提出的方式完成:

sm <- b[["smooth"]][[1]]
x1_k <- sm[["margin"]][[1]][["xp"]]
x2_k <- sm[["margin"]][[2]][["xp"]]

plot(sm(b, 1)) + l_fitRaster() + l_fitContour() + l_points() +
  geom_vline(xintercept = x1_k, linetype="dashed", color = "red", size = 1) +
  geom_hline(yintercept = x2_k, linetype="dashed", color = "red", size = 1)

如何从张量积交互(mgcv bam)中提取节点的位置?

英文:

This can be done as proposed here:

sm &lt;- b[[&quot;smooth&quot;]][[1]]
x1_k &lt;- sm[[&quot;margin&quot;]][[1]][[&quot;xp&quot;]]
x2_k &lt;- sm[[&quot;margin&quot;]][[2]][[&quot;xp&quot;]]

plot(sm(b, 1)) + l_fitRaster() + l_fitContour() + l_points() +
  geom_vline(xintercept = x1_k, linetype=&quot;dashed&quot;, color = &quot;red&quot;, size = 1) +
  geom_hline(yintercept = x2_k, linetype=&quot;dashed&quot;, color = &quot;red&quot;, size = 1)  

如何从张量积交互(mgcv bam)中提取节点的位置?

huangapple
  • 本文由 发表于 2023年7月31日 18:39:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/76802815.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定