I'm trying to do a bootstrap for my data. My data (df) has the following shape.
id v1 v2
1 1 1
1 0 1
1 0 1
2 2 0
2 1 1
2 0 0
As far as I understand, when initializing the bootstrap in R, the resampling (with reoplacement) is done on the row level, right?
so setting up sth. like:
boot_function <- function(data, i)
{boot_data <- data[i,]}
However, my first question is, how would I set this up in a scenario where I have several observations per id that need to be kept together in the bootstrap? So in my example, when doing a bootstrap, I can't simply sample among rows, but I need to sample among ids. So instead of the above
I used this one:
boot_function2 <- function(data, i)
{boot_data <- data[data$id %in% i,]}
Would that be the correct way?
And related to the above scenario I wanted to check if my approach is right, so I thought I just check how the resamples look like, but I've no idea how I can return the single bootstrap sample data frames. Any idea? (and I know, if my original data is large and I'm doing like 2000 replicates, the return object could be quite large, so i'll probably just want to spotcheck this with R=10 or so).