Show residuals with speedlm

丶灬走出姿态 提交于 2019-12-12 02:46:06

问题


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.

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"

Is there a way to show all residuals using speedlm?

When attempting to print(residuals(lmfit)) it just prints a NULL

Edit:

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

回答1:


library(speedglm)

Store the fitted value (needs more RAM):

fit <- speedlm(Sepal.Length ~ Species, data = iris, fitted = TRUE)
iris$Sepal.Length - predict(fit)

Or don't store them (needs more CPU time):

fit1 <- speedlm(Sepal.Length ~ Species, data = iris)
iris$Sepal.Length - predict(fit1, newdata = iris)


来源:https://stackoverflow.com/questions/33211136/show-residuals-with-speedlm

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!