【问题标题】:Getting Error Bootstrapping to test predictive model获取错误引导以测试预测模型
【发布时间】: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 &lt;- function(Data1, indices, formula)
  • 谢谢,这就是问题所在!

标签: r machine-learning statistics logistic-regression statistics-bootstrap


【解决方案1】:

感谢@Rui Barradas,查看 cmets 的原始帖子。

如果您阅读函数 boot::boot 的帮助页面,您会看到它调用的函数具有第一个参数数据,然后是索引,然后是其他参数。因此,将函数定义的顺序更改为 rsq

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

【讨论】:

    猜你喜欢
    • 2019-05-24
    • 2019-04-28
    • 1970-01-01
    • 2019-10-19
    • 2018-08-07
    • 1970-01-01
    • 1970-01-01
    • 2020-02-09
    • 2016-10-06
    相关资源
    最近更新 更多