如何在 R 中阻止 bootstrap?

How to block bootstrap in R?

我正在尝试 运行 块 bootstrapping 某些时间序列数据的函数(~15 年的月利率)。

我的数据在一个没有 header 的 csv 文件中,所有数据都包含一列并逐行向下。

我安装了软件包 bootstrap 因为 tsboot 对我不起作用。

这是我的代码:

testFile = read.csv("\Users\unori/sample_data.csv")
theta <- function(x){mean(x)} 
results = bootstrap(testFile,100,theta) 

它告诉我至少有 50 个错误。都说"In mean.default(x) : argument is not numeric or logical: returning NA"

怎么办?当我使用文档中的示例时,它 运行s。我想一定是我的数据是怎样的stored/imported?

提前致谢。

尝试提供一个可以重现您的问题的最小示例!检查 here 以了解如何制作最小的可重现示例。

错误消息告诉您您要计算平均值的不是数字!所以 R 只会 return NA.

调试建议:

  1. 对象'testFile'是否存在?

  2. 的输出是什么

    str(测试文件)

这对我有用:

library(bootstrap)

testFile <- cars[,1]

theta <- function(x){mean(x)} 
results = bootstrap(testFile,100,theta)