【问题标题】:Show residuals with speedlm用 speedlm 显示残差
【发布时间】:2015-10-21 14:38:31
【问题描述】:

由于我的数据集的大小,我必须使用SpeedlmfastLmbiglm。 不幸的是,我坚持使用speedlm,因为fastlm 没有update 功能,而biglm 仅支持单核。

使用 speedlm 我想显示所有残差。我知道对于lmfastlm,我可以简单地使用residuals() 函数。然而事实证明speedlm 不支持这个。

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 显示所有残差?

当尝试print(residuals(lmfit)) 时,它只会打印一个NULL

编辑:

使用@Roland提到的方法时,返回纯NA

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

【问题讨论】:

    标签: r lm


    【解决方案1】:
    library(speedglm)
    

    存储拟合值(需要更多 RAM):

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

    或者不存储它们(需要更多 CPU 时间):

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

    【讨论】:

    • 希望你不介意我只是纠正了代码中的一个小错字
    • @dickoa 非常感谢。
    • @Roland,谢谢它现在打印它们。但是,将它们存储在 RAM 中会给我以下警告:Warning messages: 1: In predict.speedlm(rval, data) : prediction from a rank-deficient fit may be misleading 2: In predict.speedlm(lmfit, newdata = res) : prediction from a rank-deficient fit may be misleading 我应该忽略这个吗?
    • 不,你不应该忽略这一点。
    • 当然,调查一下为什么你有一个排名不足的契合度。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-03-04
    • 1970-01-01
    • 2020-03-25
    • 2020-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多