【发布时间】:2023-03-31 03:05:02
【问题描述】:
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
背景信息:我正在使用线性回归创建预测模型。我想测试我的预测模型,通过一些研究,我决定使用 Bootstrapping Method。
【问题讨论】:
-
如果您阅读函数
boot::boot的帮助页面,您会看到它调用的函数有 first 参数data,然后是 @ 987654325@,然后是其他人。因此,将函数定义的顺序更改为rsq <- function(Data1, indices, formula)。 -
谢谢,这就是问题所在!
标签: r machine-learning statistics logistic-regression statistics-bootstrap