r语言 - 获取错误引导以测试预测模型


rsq <- function(formula, Data1, indices) {
d <- Data1[indices,] # allows boot to select sample 
fit <- lm(formula, Data1=d)
return(summary(fit)$r.square)
}
results = boot(data = Data1, statistic = rsq, R = 500)

当我执行代码时,出现以下错误:

Error in Data1[indices,] : incorrect number of dimensions

背景信息:我正在使用线性回归创建一个预测模型。我想测试我的预测模型,通过一些研究,我决定使用引导方法。

功劳归@Rui巴拉达斯,检查原始帖子的评论。

如果您阅读函数 boot::boot 的帮助页面,您将看到它调用的函数首先具有参数数据,然后是索引,然后是其他参数数据。因此,将函数定义的顺序更改为rsq <-函数(Data1,索引,公式(

我遇到的另一个问题是我没有定义函数。

最新更新