【发布时间】:2016-03-31 13:12:20
【问题描述】:
似乎从函数内部或通过lapply 调用lm() 会破坏与拟合相关联的$call。最小的工作示例:
> library(MASS)
> dat <- data.frame(x = 1:100, y=1:100)
> dat <- within(dat, z <- x + log(y) + rnorm(100))
> fits <- lapply(list(z ~ x + y, z ~ x + log(y)), lm, dat)
> stepAIC(fits[[1]]) # <-- error when I try to use the fit in other functions
Error in eval(expr, envir, enclos) : could not find function "FUN"
> fits[[1]]$call
FUN(formula = X[[i]], data = ..1) # Aha -- this must be why -- $call is screwed up
如何解决此问题并防止出现上述错误?
【问题讨论】:
-
@coffeinjunky 不,只是为了这个玩具示例,事情保持简单
-
这里有一个类似的问题,供参考stackoverflow.com/q/7666807/210673
标签: r regression linear-regression lm