【发布时间】:2016-05-08 06:22:15
【问题描述】:
我正在使用 dplyr/broom 包对多个传感器进行线性回归。当我在 do 语句中使用 lm() 时,broom 中的glance() 函数将不起作用,但如果我使用 biglm() 则将起作用。这不是问题,但我想要 r^2、F-Statistic 和 p-val,对于传统的 lm(),glance 返回相当漂亮。
我在别处找过,找不到类似的错误:
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
pastebin 上的 R 会话信息,如果您愿意的话here!
【问题讨论】:
-
当由于模型奇异性而没有定义至少一个系数并且因此在
lm对象中没有返回 F 统计量时,我可以重现这一点 - 所以glance字面上找不到 @987654328 @.