【发布时间】:2018-01-09 22:20:38
【问题描述】:
我想了解predict.lmfunction 在 R 中是如何工作的。因此,我在控制台中输入函数的名称以查看代码,将代码复制到新脚本并调用 pred 到新函数:
pred <- function (object, newdata, se.fit = FALSE, scale = NULL, df = Inf,
interval = c("none", "confidence", "prediction"), level = 0.95,
type = c("response", "terms"), terms = NULL, na.action = na.pass,
pred.var = res.var/weights, weights = 1, ...)
{
<here goes the body of the predict.lm function which
I do not copy to the post so it remains readable>
}
然后我拟合一个模型来检查一切是否正常,并使用新函数 pred 进行预测,该函数是 predict.lm 函数的副本:
fit <- lm(Sepal.Length ~ Species, data = iris)
new_obs = data.frame(Species = "versicolor")
print(pred(fit, newdata = new_obs, interval = "prediction"))
但后来我得到了这个错误:
Error in pred(fit, newdata = newobs, interval = "prediction" :
could not fund function "qr.lm"
我搜索了函数qr.lm,但找不到。我只找到qr 函数。
qr.lm 函数在哪里?如何访问它?
【问题讨论】: