2017-08-02 53 views
0

我想了解R函数predict.lm如何在R中工作。所以,我在控制台中输入函数的名称来查看代码,将代码复制到新的脚本和呼叫Pred提供给新的功能:R - `qr.lm`函数在哪里

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函数在哪里?我如何访问它?

+0

也许感兴趣https://stackoverflow.com/questions/19226816/how-can-i-view-the-source-code-for-a-function – user20650

回答

2

使用这种尝试......

stats:::qr.lm 

:::是你如何访问是内部的一个包对象。