R - `qr.lm` 函数在哪里

Edu*_*rdo 1 r predict lm

我想了解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>

}
Run Code Online (Sandbox Code Playgroud)

然后我拟合一个模型来检查一切是否正常,并使用作为函数pred副本的新函数进行预测predict.lm

fit <- lm(Sepal.Length ~ Species, data = iris)
new_obs = data.frame(Species = "versicolor")
print(pred(fit, newdata = new_obs, interval = "prediction"))
Run Code Online (Sandbox Code Playgroud)

但是后来我收到了这个错误:

Error in pred(fit, newdata = newobs, interval = "prediction" :
  could not fund function "qr.lm"
Run Code Online (Sandbox Code Playgroud)

我已经搜索了函数qr.lm,但我找不到它。我只找到qr功能。

qr.lm功能在哪里以及如何访问它?

Lyn*_*akr 5

尝试使用这个...

stats:::qr.lm
Run Code Online (Sandbox Code Playgroud)

::: 是访问包内部对象的方式。