R - `qr.lm` 函数在哪里
R - Where is the `qr.lm` function
我想了解 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
函数在哪里,我如何访问它?
尝试使用这个...
stats:::qr.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>
}
然后我拟合一个模型来检查一切是否正常,并使用新函数 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
函数在哪里,我如何访问它?
尝试使用这个...
stats:::qr.lm
:::
是访问包内部对象的方式。