英文:
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()
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 <- 10e4
dat <- data.frame("x1" = rnorm(n), "x2" = rnorm(n), "x3" = rnorm(n))
dat$y <- with(dat, sin(x1) + 0.5*x2^2 + 0.2*x3 + 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()
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)
英文:
This can be done as proposed here:
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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论