找不到函数plot.gam [英] Could not find function plot.gam

查看:359
本文介绍了找不到函数plot.gam的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究"R中的应用程序进行统计学习简介"(ISLR),我只停留在第295页的一部分上,这是广义可加模型的实验室.当我运行以下代码时,出现错误Error in plot.gam(gam1, se = TRUE, col = "red") : could not find function "plot.gam".

I'm going through the "Introduction to Statistical Learning with Applications in R" (ISLR), and I'm stuck on a part on page 295, the lab on Generalized Additive Models. When I run the following code I get an error 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 book says that plot.gam should be part of the general plot function, so why can't R find it? Am I supposed to be doing something differently? I tried unsuccessfully to re-download the plot library with install.packages('plot', repos='http://cran.us.r-project.org').

这使我感到困惑,因为书上写着这样:

This confuses me because the book says this:

通用plot()函数认识到gam2是类的对象 gam,并调用适当的plot.gam()方法. plot.gam()gam1不是gam类,而是lm类,我们可以 仍然在上面使用plot.gam().图7.11是使用 以下表达式:

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(gam1, se=TRUE, col="red")

推荐答案

使用plot.Gam而不是plot.gam.

软件更新,但本书没有跟上.查看 gam软件包的更改日志,我们可以看到情况在2018年初有所改变:

Software updates, but the book has not kept up. Checking the change log for the gam package, we can see that the case was changed in early 2018:

2018-02-06 Trevor Hastie版本1.15 *将主要类别从"gam"更改为"Gam",以避免与mgcv(grr!)冲突

2018-02-06 Trevor Hastie version 1.15 * major change class "gam" to "Gam" to avoid conflict with mgcv (grr!)

这篇关于找不到函数plot.gam的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆