我想知道predict.lm
函数在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
功能在哪里以及如何访问它?