Search code examples
rblockrobustness

How to block bootstrap in R?


I'm trying to run a block bootstrapping function on some time series data (monthly interest rates for ~15 years).

My data is in a csv file with no header, all comprising one column and going down by row.

I installed the package bootstrap because tsboot wouldn't work for me.

Here is my code:

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

It tells me there are at least 50 errors. All of them say "In mean.default(x) : argument is not numeric or logical: returning NA"

What to do? It runs when I use the example in the documentation. I think it must be how my data is stored/imported?

Thanks in advance.


Solution

  • Try to supply a working, minimal example that reproduces your problem! Check here to see how to make a minimal reproducible example.

    The error messages tells you that the thing you want to calculate the mean of, is not a number! So R will just return NA.

    Suggestions for debugging:

    1. Does the object 'testFile' exist?

    2. What is the output of

      str(testFile)

    This works for me:

    library(bootstrap)
    
    testFile <- cars[,1]
    
    theta <- function(x){mean(x)} 
    results = bootstrap(testFile,100,theta)