首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Speedlm更新“需要调用组件的对象”

Speedlm更新“需要调用组件的对象”
EN

Stack Overflow用户
提问于 2015-10-13 13:41:37
回答 1查看 2.8K关注 0票数 2

我试图使用speedlm (快速箱)的update选项,因为我没有足够的内存一次计算整个模型,而biglm只使用一个CPU。

下面的代码是一个可复制的错误示例。

代码语言:javascript
复制
library(speedglm)
formula <- Sepal.Length ~ Sepal.Width
chunk1 <- iris[1:10,]
chunk2 <- iris[11:20,]
chunk3 <- iris[21:30,]
lmfit <- speedlm(formula, chunk1)
lmfit <- update(lmfit, chunk2)
lmfit <- update(lmfit, chunk3)

我得到了以下错误:

代码语言:javascript
复制
> lmfit <- speedlm(formula, chunk1)
> lmfit <- update(lmfit, chunk2)
> lmfit <- update(lmfit, chunk3)
Error in update.default(lmfit, chunk3) : 
  need an object with call component
> 

如果是因为有了update而不是updateWithMoreData,那么在使用chunk2进行更新之后,我就已经预料到了这个错误。

我想知道一种解决这个问题的方法,或者我必须使用另一种方法。

提前感谢!

使用updateWithMoreData获取以下错误

代码语言:javascript
复制
> lmfit <- speedlm(formula, chunk1)
> lmfit <- updateWithMoreData(lmfit, chunk2)
Error: object of type 'symbol' is not subsettable
> lmfit <- updateWithMoreData(lmfit, chunk3)
Error: object of type 'symbol' is not subsettable
> 

下面的代码起作用了,道具到@LyzandeR

代码语言:javascript
复制
> library(speedglm)
> chunk1 <- iris[1:10,]
> chunk2 <- iris[11:20,]
> chunk3 <- iris[21:30,]
> lmfit  <- speedlm(Sepal.Length ~ Sepal.Width, chunk1)
> 
> for (i in list(11,20, 21:30)){
+   lmfit2 <- updateWithMoreData(lmfit, iris[i,])
+ }
> lmfit2
Linear Regression Model of class 'speedlm':

Call:  speedlm(formula = Sepal.Length ~ Sepal.Width, data = chunk1) 

Coefficients:
(Intercept)  Sepal.Width  
     2.9876       0.5813  

> 
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-10-13 14:02:47

为了使用update更新您的模型,您需要使用updateWithMoreData作为@Roland的注释。不过有个陷阱。

如果你像这样使用代码,你会得到:

代码语言:javascript
复制
library(speedglm)
formula <- Sepal.Length ~ Sepal.Width
chunk1 <- iris[1:10,]
chunk2 <- iris[11:20,]
chunk3 <- iris[21:30,]
lmfit <- speedlm(formula, chunk1)
#runs fine up to here

#but this gives an error
lmfit2 <- updateWithMoreData(lmfit, chunk2)
Error: object of type 'symbol' is not subsettable

显然,这是因为它试图调用它(从跟踪):

as.formula(object$call[[2]])

它失败了,因为lmfit$call[[2]]返回formula。但是,如果将其更改为此,则可以:

代码语言:javascript
复制
library(speedglm)
chunk1 <- iris[1:10,]
chunk2 <- iris[11:20,]
chunk3 <- iris[21:30,]
#use the actual formula below so lmfit$call[[2]] will return it
#and now all the three lines below work fine
lmfit  <- speedlm(Sepal.Length ~ Sepal.Width, chunk1)
lmfit2 <- updateWithMoreData(lmfit, chunk2)
lmfit3 <- updateWithMoreData(lmfit, chunk3)

注意,当您打印它们时,两者都会说它们是块1,因为调用保持不变,但是结果是正确的:

输出:

代码语言:javascript
复制
> lmfit2
Linear Regression Model of class 'speedlm':

Call:  speedlm(formula = Sepal.Length ~ Sepal.Width, data = chunk1) 

Coefficients:
(Intercept)  Sepal.Width  
     1.8398       0.9181  

> lmfit
Linear Regression Model of class 'speedlm':

Call:  speedlm(formula = Sepal.Length ~ Sepal.Width, data = chunk1) 

Coefficients:
(Intercept)  Sepal.Width  
     2.3882       0.7468  
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33104274

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档