我试图使用speedlm (快速箱)的update选项,因为我没有足够的内存一次计算整个模型,而biglm只使用一个CPU。
下面的代码是一个可复制的错误示例。
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)我得到了以下错误:
> 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获取以下错误
> 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
> 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
> 发布于 2015-10-13 14:02:47
为了使用update更新您的模型,您需要使用updateWithMoreData作为@Roland的注释。不过有个陷阱。
如果你像这样使用代码,你会得到:
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。但是,如果将其更改为此,则可以:
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,因为调用保持不变,但是结果是正确的:
输出:
> 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 https://stackoverflow.com/questions/33104274
复制相似问题