我正在使用dplyr/broom软件包对多个传感器进行线性回归。当我在do语句中使用lm()时,broom的glance()函数将无法工作,但如果我使用biglm()则可以。虽然这不是问题,但我想要像传统的lm()一样,通过glance返回的r ^ 2,F-Statistic和p-val。
我已经查找了其他地方,但无法找到类似的错误案例:
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 如果需要R会话信息,请在pastebin上查看这里!
lm
对象中没有返回F统计量,因此glance
无法找到fstatistic
。 - aosmith