问题
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