我正在使用dplyr/broom包对多个传感器进行线性回归.当我在do语句中使用lm()时,来自扫帚的glance()函数将无法工作,但如果我使用biglm()则会这样.这不会是一个问题,但我希望r ^ 2,F-Statistic和p-val对传统的lm()来说非常漂亮.
我已经在其他地方寻找过,并且找不到与此错误类似的情况:
Error in data.frame(r.squared = r.squared, adj.r.squared = adj.r.squared, :
object 'fstatistic' not found
Run Code Online (Sandbox Code Playgroud)
可能的预感:
?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."
Run Code Online (Sandbox Code Playgroud)
这是代码:
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
Run Code Online (Sandbox Code Playgroud)
我讨厌上传整个数据框,因为我知道它在S/O上通常是不可接受的,但我不确定如果不这样做就可以创建一个可重现的例子. https://www.dropbox.com/s/pt6xe4jdxj743ka/testdf.Rda?dl=0
关于pastebin的R会话信息,如果你想在这里!
它看起来像一个糟糕的模型ErrorDf.我诊断它运行for循环.
for (i in 1:nrow(ErrorDf)){
print(i)
glance(ErrorDf$fit[[i]])
}
Run Code Online (Sandbox Code Playgroud)
value模型#94 看起来没有系数可以估算.我没有做进一步的调查,但它提出了一个有趣的问题,broom应该如何处理.