我看到已经提出了这个主题,但是通过阅读讨论并不能解决我的问题。即使我使用网络上的简单示例,例如,我也会一遍又一遍地收到此错误消息。来自https://medium.com/data-distilled/residual-plots-part-4-residuals-vs-leverage-plot-14aeed009ef7:
model <- glm(dist ~ speed, data = cars, family = gaussian)
plot(model)
Error in xy.coords(x, y, xlabel, ylabel, log) :
'x' is a list, but does not have components 'x' and 'y'
命令“ plot”实际上应该“知道”如何处理对象“ model”,不是吗?
与lm相同:
x = runif(200,0,2)
y = 2*x + 1 + rnorm(200,0,1)
res = lm(y ~ x)
plot(res)
Error in xy.coords(x, y, xlabel, ylabel, log) :
'x' is a list, but does not have components 'x' and 'y'
class(res)
[1] "lm"
methods(class = "lm") # plot is among them!
qqPlot(res)
Error in model.frame.default(formula = y ~ x, na.action = "na.exclude", :
invalid type (list) for variable 'x'
有什么建议吗?
这很奇怪。两组代码都对我有用。由于我无法复制您的环境,因此我只能建议您可以尝试的几件事:
stats::lm
代替lm
df
是bug的常见来源)->尝试以其他方式命名您的对象]]