Using the boot command to generate bootstrap in R has some erros

Viewed 17

I have a data frame with many columns say 100. The first column contains categories such as "System 1", "System 2", and the second column has numbers that represent the 0's and 1's. Please see below :

For example:

SYSTEM Q1 Q2
S1 0 1
S1 1 0
S2 1 1
S2 0 0
S2 1 1

I want to prepare a function to bootstrap confidence intervals.

Here is my data :

m <- 100; n <- 5
set.seed(42)
df2 <- data.frame(SYSTEM=rep(c('S1', 'S2'), each=n/2), matrix(sample(0:1, m*n, replace=TRUE), m, n))
names(df2)[-1] <- paste0('Q', 1:n)

Here is my code : Before calling boot, I want to to define a function that will return the statistic(s) that would like to bootstrap. The first argument passed to the function should be my dataset. The second argument can be an index vector of the observations in my dataset to use or a frequency or weight vector that informs the sampling probabilities. I want to group my system in the fuction.My goal is to compare Q1[system1]vs. Q1[System2].

fc <- function(d, i){
  d2 <- d[i,] %>% 
    filter(SYSTEM==i) 
  return(cor(d2$Q1, d2$Q1))
}

set.seed(626)
bootcorr <- boot(df2, fc, R=500)
bootcorr

the error as fllow :

rror in d[i, ] : object of type 'builtin' is not subsettable. How to fix the error?

Thank you

0 Answers
Related