【问题标题】:biglm finds the wrong data.frame to take the data frombiglm 发现错误的 data.frame 从中获取数据
【发布时间】:2016-01-09 18:52:44
【问题描述】:

我正在尝试创建我的数据集块来运行biglm。 (使用 fastLm 我需要 350Gb 的 RAM)

我的完整数据集称为res。作为实验,我将大小大幅减少到 10.000 行。我想创建与 biglm 一起使用的块。

library(biglm)

formula <- iris$Sepal.Length ~ iris$Sepal.Width

test <- iris[1:10,]

biglm(formula, test)

不知何故,我得到以下输出:

> test <- iris[1:10,]
> test
   Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1           5.1         3.5          1.4         0.2  setosa
2           4.9         3.0          1.4         0.2  setosa
3           4.7         3.2          1.3         0.2  setosa
4           4.6         3.1          1.5         0.2  setosa
5           5.0         3.6          1.4         0.2  setosa
6           5.4         3.9          1.7         0.4  setosa
7           4.6         3.4          1.4         0.3  setosa
8           5.0         3.4          1.5         0.2  setosa
9           4.4         2.9          1.4         0.2  setosa
10          4.9         3.1          1.5         0.1  setosa

您可以在上面看到矩阵test 包含10 行。然而,当运行 biglm 时,它显示的样本大小为 150

> biglm(formula, test)
Large data regression model: biglm(formula, test)
Sample size =  150 

看起来它使用 iris 而不是 test.. 这怎么可能?如何让 biglm 以我想要的方式使用 chunk1?

【问题讨论】:

  • 我将代码更新为可重现的示例

标签: r assign lm chunks chunking


【解决方案1】:

我怀疑下面一行是罪魁祸首:

formula <- iris$Sepal.Length ~ iris$Sepal.Width

您在公式中明确引用iris 数据集的位置。这将导致 R 在调用 lm 时尝试查找 iris 数据集,它在全局环境中找到(由于 R 的范围规则)。

在公式中,您通常不使用向量,而只是使用列名:

formula <- Sepal.Length ~ Sepal.Width

这将确保公式仅包含列(或变量)名称,这些名称将在传递的数据中找到lm。所以,lm 将使用test 代替iris

【讨论】:

  • 非常感谢!不敢相信我今天被困了多久!
猜你喜欢
  • 2020-09-15
  • 2012-07-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多