我正在使用 dplyr/broom 包对多个传感器进行线性回归。当我在 do 语句中使用 lm() 时,broom 中的lancet() 函数将不起作用,但如果我使用 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
可能的预感:
?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 https://www.dropbox.com/s/pt6xe4jdxj743ka/testdf.Rda?dl=0
如果您愿意的话,请在pastebin上查看R会话信息here http://pastebin.com/n6q8XhKk!