5

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?

Eduardo
  • 2,405
  • 3
  • 14
  • 19
  • perhaps of interest https://stackoverflow.com/questions/19226816/how-can-i-view-the-source-code-for-a-function – user20650 Aug 03 '17 at 09:43

1 Answers1

7

Try using this...

stats:::qr.lm

::: is how you access objects that are internal to a package.

Dan
  • 11,370
  • 4
  • 43
  • 68