本文介绍了用speedlm显示残差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于数据集的大小,我必须使用 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我想显示所有残差.我知道对于lmfastlm,我可以简单地使用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显示残差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 14:56