问题描述
由于数据集的大小,我必须使用 Speedlm
, fastLm
或 biglm
.不幸的是,我坚持使用speedlm
,因为fastlm
没有update
函数,并且biglm
仅支持单核.
Due to the size of my dataset I'm bound to use Speedlm
, fastLm
or biglm
. Unfortunately I'm stuck to using speedlm
as fastlm
doesn't have an update
function, and biglm
only supports single core.
使用speedlm我想显示所有残差.我知道对于lm
或fastlm
,我可以简单地使用residuals()
函数.但是事实证明speedlm
不支持此功能.
Using speedlm I want to show all residuals. I know that for lm
or fastlm
I can simply use the residuals()
function. However it turns out speedlm
doesn't support this.
lmfit <- speedglm(formula , res)
print(names(lmfit))
[1] "coefficients" "coef" "df.residual" "XTX" "Xy" "nobs" "nvar" "ok" "A" "RSS" "rank" "pivot" "sparse" "yy" "X1X" "intercept" "method" "terms" "call"
lmfit <- fastLm(formula, res)
print(names(lmfit))
[1] "coefficients" "stderr" "df.residual" "fitted.values" "residuals" "call" "intercept" "formula"
是否可以使用speedlm
显示所有残差?
Is there a way to show all residuals using speedlm
?
尝试print(residuals(lmfit))
时仅打印NULL
使用@Roland提及的方法时,它仅返回NA
的
When using the method mentioned by @Roland, it returns purely NA
's
lmfit <- speedlm(formula , res, fitted=TRUE)
resids <- res$Daily_gain - predict(lmfit, newdata=res)
print(summary(resids))
# Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
# NA NA NA NaN NA NA 829780
推荐答案
library(speedglm)
存储拟合值(需要更多的RAM):
Store the fitted value (needs more RAM):
fit <- speedlm(Sepal.Length ~ Species, data = iris, fitted = TRUE)
iris$Sepal.Length - predict(fit)
或者不存储它们(需要更多的CPU时间):
Or don't store them (needs more CPU time):
fit1 <- speedlm(Sepal.Length ~ Species, data = iris)
iris$Sepal.Length - predict(fit1, newdata = iris)
这篇关于用speedlm显示残差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!