找不到函数 plot.gam
Could not find function plot.gam
我正在学习 "Introduction to Statistical Learning with Applications in R" (ISLR),我卡在了第 295 页的一个部分,广义加性模型实验室。当我 运行 以下代码时,出现错误 Error in plot.gam(gam1, se = TRUE, col = "red") : could not find function "plot.gam"
.
library(ISLR)
gam1 = lm(wage ~ ns(year, 4) + ns(age, 5) + education, data=Wage)
par(mfrow=c(1,3))
plot.gam(gam1, se=TRUE, col="red")
书上说plot.gam
应该是一般plot
函数的一部分,为什么R找不到呢?我应该做些不同的事情吗?我尝试使用 install.packages('plot', repos='http://cran.us.r-project.org')
重新下载绘图库,但没有成功。
这让我很困惑,因为书上是这样说的:
The generic plot() function recognizes that gam2 is an object of class
gam, andinvokestheappropriateplot.gam()method.Conveniently,eventhough
plot.gam() gam1 is not of class gam but rather of class lm, we can
still use plot.gam() on it. Figure 7.11 was produced using the
following expression:
plot.gam(gam1, se=TRUE, col="red")
使用 plot.Gam
而不是 plot.gam
。
软件更新了,但是书没跟上。检查change log for the gam
package,我们可以看到2018年初的情况发生了变化:
2018-02-06 Trevor Hastie version 1.15
* major change class "gam" to "Gam" to avoid conflict with mgcv (grr!)
我正在学习 "Introduction to Statistical Learning with Applications in R" (ISLR),我卡在了第 295 页的一个部分,广义加性模型实验室。当我 运行 以下代码时,出现错误 Error in plot.gam(gam1, se = TRUE, col = "red") : could not find function "plot.gam"
.
library(ISLR)
gam1 = lm(wage ~ ns(year, 4) + ns(age, 5) + education, data=Wage)
par(mfrow=c(1,3))
plot.gam(gam1, se=TRUE, col="red")
书上说plot.gam
应该是一般plot
函数的一部分,为什么R找不到呢?我应该做些不同的事情吗?我尝试使用 install.packages('plot', repos='http://cran.us.r-project.org')
重新下载绘图库,但没有成功。
这让我很困惑,因为书上是这样说的:
The generic plot() function recognizes that gam2 is an object of class gam, andinvokestheappropriateplot.gam()method.Conveniently,eventhough plot.gam() gam1 is not of class gam but rather of class lm, we can still use plot.gam() on it. Figure 7.11 was produced using the following expression:
plot.gam(gam1, se=TRUE, col="red")
使用 plot.Gam
而不是 plot.gam
。
软件更新了,但是书没跟上。检查change log for the gam
package,我们可以看到2018年初的情况发生了变化:
2018-02-06 Trevor Hastie version 1.15 * major change class "gam" to "Gam" to avoid conflict with mgcv (grr!)