我的GAM曲线正在向下移动。拦截有什么问题吗?我使用相同的代码Introduction to statistical learning
...任何帮助的感激..为什么我的GAM适合似乎没有正确的概念? [R]
下面的代码。我模拟了一些数据(有噪声的直线),并使用bootstrap多次适应GAM。 (我花了一段时间来弄清楚如何绘制多个GAM在一个图表。由于this post萨姆的回答千篇一律,和this post)
library(gam)
N = 1e2
set.seed(123)
dat = data.frame(x = 1:N,
y = seq(0, 5, length = N) + rnorm(N, mean = 0, sd = 2))
plot(dat$x, dat$y, xlim = c(1,100), ylim = c(-5,10))
gamFit = vector('list', 5)
for (ii in 1:5){
ind = sample(1:N, N, replace = T) #bootstrap
gamFit[[ii]] = gam(y ~ s(x, 10), data = dat, subset = ind)
par(new=T)
plot(gamFit[[ii]], col = 'blue',
xlim = c(1,100), ylim = c(-5,10),
axes = F, xlab='', ylab='')
}
我没有准确的答案,但是如果从两次调用'plot'中删除'xlim'和'ylim',那么问题就会消失。然而,仍然试图找出确切的问题是什么。 –