Broom / Dplyr error with glance()当使用lm而不是biglm时 [英] Broom/Dplyr error with glance() when using lm instead of biglm

查看:139
本文介绍了Broom / Dplyr error with glance()当使用lm而不是biglm时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用dplyr / broom软件包对多个传感器进行线性回归。当我在do语句中使用lm()时,扫帚的glance()函数将不会工作,但是如果我使用biglm()。这不是一个问题,但是我希望r ^ 2,F-Statistic和p-val这样一来,传统的lm()返回相当漂亮。

I am using the dplyr/broom package to do linear regressions for multiple sensors. The glance() function from broom will not work when I use lm() within the do statement, but will if I use biglm(). This wouldn't be an issue, but I would like the r^2, F-Statistic and p-val that glance returns quite beautifully for the traditional lm().

我曾经看过其他地方,找不到类似的错误:

I've looked elsewhere and cannot find a similar case with this error:

Error in data.frame(r.squared = r.squared, adj.r.squared = adj.r.squared,  : 
 object 'fstatistic' not found

可能的hunches:

Possible hunches:

?Anova 
"The comparison between two or more models will only be valid if they are 
fitted to the same dataset. This may be a problem if there are missing
values and R's default of na.action = na.omit is used."

这是代码:

library(tidyr)
library(broom)
library(biglm) # if not install.packages("biglm")
library(dplyr)
regressionBig <- tidied_rm_outliers %>%
group_by(sensor_name, Lot.Tool, Lot.Module, Recipe, Step, Stage, MEAS_TYPE) %>%
do(fit = biglm(MEAS_AVG ~ value, data = .)) #note biglm is used

regressionBig 

#extract the r^2 from the complex list type from the data frame we just stored

glances <- regressionBig %>% glance(fit)
glances %>% 
  ungroup() %>%
  arrange(desc(r.squared))
#Biglm works but if i try the same thing with regular lm It errors on glance() 

ErrorDf <- tidied_rm_outliers %>%
  group_by(sensor_name, Lot.Tool, Lot.Module, Recipe, Step, Stage, MEAS_TYPE) %>% 
  do(fit = lm(MEAS_AVG ~ value, data = .)) #note lm is normal
ErrorDf %>% glance(fit)

#Error in data.frame(r.squared = r.squared, adj.r.squared = adj.r.squared,  : 
#object 'fstatistic' not found

我讨厌上传整个数据框架,因为我知道它通常是不可接受的S / O,但我不知道我可以创建一个可重现的例子,而不这样做。
https://www.dropbox.com/s/pt6xe4jdxj743ka /testdf.Rda?dl=0

I hate to upload the entire data frame as I know it's usually not acceptable on S/O but I am not sure I can create a reproducible example without doing so. https://www.dropbox.com/s/pt6xe4jdxj743ka/testdf.Rda?dl=0

如果您希望使用pastebin的R会话信息这里

R session info on pastebin if you would like it here!

推荐答案

它在 ErrorDf 。我确定它运行一个循环。

It looks like a bad model in ErrorDf. I diagnosed it running a for loop.

for (i in 1:nrow(ErrorDf)){
  print(i)
  glance(ErrorDf$fit[[i]])
}

对于模型#94,可以估计的系数。我还没有做任何进一步的调查,但它带来了一个有趣的问题,如何扫帚应该处理。

It looks like no coefficient for value could be estimated for model # 94. I haven't done any further investigation, but it brings up the interesting question of how broom should handle that.

这篇关于Broom / Dplyr error with glance()当使用lm而不是biglm时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆