0
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)

When I execute the code, I get the following error:

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

Background info: I am creating a predictive model using Linear Regressions. I would like to test my Predictive Model and through some research, I decided to use the Bootstrapping Method.

StupidWolf
  • 45,075
  • 17
  • 40
  • 72
MhQ-6
  • 328
  • 3
  • 11
  • 1
    If you read the help page for function `boot::boot` you will see that the function it calls has ***first*** argument `data`, then `indices`, then others. So change the order of your function definition to `rsq <- function(Data1, indices, formula)`. – Rui Barradas Sep 19 '18 at 21:14
  • Thank you, that was the issue! – MhQ-6 Sep 20 '18 at 14:37

1 Answers1

0

Credit goes to @Rui Barradas, check comments for original post.

If you read the help page for function boot::boot you will see that the function it calls has first argument data, then indices, then others. So change the order of your function definition to rsq <- function(Data1, indices, formula)

Another problem that I had was that I didn't define the Function.

MhQ-6
  • 328
  • 3
  • 11