R - Where is the `qr.lm` function

Viewed 1679

I'm tring to understand how does predict.lmfunction works in R. So, I type the name of the function in the console to see the code, copy the code to a new script and call pred to the new function:

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>

}

Then I fit a model to check that everything is ok and ask for a prediction using the new function pred which is a copy of predict.lm function:

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

But then I got this error:

Error in pred(fit, newdata = newobs, interval = "prediction" :
  could not fund function "qr.lm"

I've searched for the function qr.lm, but I cannot find it. I only find the qr function.

Where is the qr.lm function and how can I access it?

1 Answers
Related