有没有办法在 sparklyr 中使用 ml_linear_regression 显示标准错误?

Is there a way to display standard errors with ml_linear_regression in sparklyr?

当运行使用sparklyr进行线性回归时,例如:

cached_cars %>%
  ml_linear_regression(mpg ~ .) %>%
  summary()

结果不包括标准误差

Deviance Residuals:
     Min       1Q   Median       3Q      Max 
-3.47339 -1.37936 -0.06554  1.05105  4.39057 

Coefficients:
(Intercept) cyl_cyl_8.0 cyl_cyl_4.0        disp          hp        drat
16.15953652  3.29774653  1.66030673  0.01391241 -0.04612835  0.02635025
          wt        qsec          vs          am       gear        carb 
 -3.80624757  0.64695710  1.74738689  2.61726546 0.76402917  0.50935118  

R-Squared: 0.8816
Root Mean Squared Error: 2.041
  1. 运行回归时有没有办法显示标准误差?
  2. 有没有办法在 sparklyr 中对标准错误进行聚类?
  3. 我也一直在尝试 运行 sparklyr 中具有多组固定效应的线性模型。在 base R 中,我用 felm 这样做了。有没有人有在 sparklyr 中这样做的经验?

也非常感谢使用 SparkR 的解决方案。

  1. 我想你要找的是 tidy()。所以在你的情况下:
regression1 <- cached_cars %>%
  ml_linear_regression(mpg ~ .) 
tidy(regression1)

至于聚类标准误差和固定效应我不知道。

我在 community.rstudio.com 收到了第一个问题的有用答案。

一淘里的回答如下:

library(sparklyr)

spark_version <- "2.4.4" # This is the version of Spark I ran this example code with,
# but I think everything that follows should work in all versions of Spark anyways

sc <- spark_connect(master = "local", version = spark_version)

cached_cars <- copy_to(sc, mtcars)
model <- cached_cars %>%
  ml_linear_regression(mpg ~ .)

coeff_std_errs <- invoke(model$model$.jobj, "summary") %>%
  invoke("coefficientStandardErrors")

print(coeff_std_errs)