【问题标题】:biglm - Error: $ operator is invalid for atomic vectorsbiglm - 错误:$ 运算符对原子向量无效
【发布时间】:2019-05-08 22:39:49
【问题描述】:

我正在尝试在非常大的数据集(数百万行)上运行广义线性模型。然而,R 似乎无法处理分析,因为我不断收到内存分配错误(无法分配大小的向量......等等)。

数据适合 RAM,但似乎太大而无法估计复杂模型。作为一种解决方案,我正在探索使用 ff 包将 r 的内存中存储机制替换为磁盘存储。

我已成功(我认为)将数据卸载到我的硬盘,但是当我尝试估计 glm(通过 biglm 包)时,我收到以下错误:

Error: $ operator is invalid for atomic vectors

我不确定为什么在使用 bigglm 函数时会出现这个特定错误。当我在完整数据集上运行 glm 时,它不会给我这个特定的错误,尽管可能 r 在足够远以触发“操作员无效”错误之前内存不足。

我在下面提供了一个示例数据集和代码。请注意,标准 glm 在此示例数据上运行得很好。使用 biglm 时出现问题。

如果您有任何问题,请告诉我。

提前谢谢你!

#Load required packages
library(readr)
library(ff)
library(ffbase)
library(LaF)
library(biglm)

#Create sample data
df <- data.frame("id" = as.character(1:20), "group" = rep(seq(1:5), 4), 
                 "x1" = as.character(rep(c("a", "b", "c", "d"), 5)),
                 "x2" = rnorm(20, 50, 1), y = sample(0:1, 20, replace=T),
                 stringsAsFactors = FALSE)

#Write data to file
write_csv(df, "df.csv")

#Create connection to sample data using laf
con <- laf_open_csv(filename = "df.csv",
                    column_types = c("string", "string", "string", 
                                     "double", "string"),
                    column_names = c("id", "group", "x1", "x2", "y"),
                    skip = 1)

#Use LaF to import data into ffdf object
ff <- laf_to_ffdf(laf = con)

#Fit glm on data stored in RAM (note this model runs fine)
fit.glm <- glm(y ~ factor(x1) + x2 + factor(group), data=df, 
               family="binomial")

#Fit glm on data stored on hard-drive (note this model fails)
fit.big <- bigglm(y ~ factor(x1) + x2 + factor(group), data=ff, 
                  family="binomial")

【问题讨论】:

    标签: bigdata out-of-memory ff


    【解决方案1】:

    您使用了错误的家庭论点。

    library(ffbase)
    library(biglm)
    df <- data.frame("id" = factor(as.character(1:20)), "group" = factor(rep(seq(1:5), 4)), 
                     "x1" = factor(as.character(rep(c("a", "b", "c", "d"), 5))),
                     "x2" = rnorm(20, 50, 1), y = sample(0:1, 20, replace=T),
                     stringsAsFactors = FALSE)
    d <- as.ffdf(df)
    fit.big <- bigglm.ffdf(y ~ x1 + x2 , data = d, 
                           family = binomial(link = "logit"), chunksize = 3)
    

    【讨论】:

      猜你喜欢
      • 2015-10-02
      • 2020-06-21
      • 2021-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-23
      相关资源
      最近更新 更多