I'm trying to work through the code in a bootstrap simulation on this post with two major hurdles. First, the few times I have played with bootstrapping, I have done it without using the {boot}
package, and relying on functions like replicate
, or simply loops. And second, and the main object of my question, I don't know what the function xor
takes in as inputs, and what it ultimately does:
n <- 1000
dat <- c("A", rep("B", n-1))
indicator <- function(x, ndx) xor("A"%in%x[ndx], TRUE)
I see that it assesses whether "A"
is in x
and returns FALSE
if it actually is in it. The issue comes with the input ndx
. It probably stands for "index", and this is likely connected with the bootstrapping that follows:
p_hat <- function(dat, m=1e3){
foo <- boot(data=dat, statistic=indicator, R=m)
1/mean(foo$t)
}
reps <- replicate(100, p_hat(dat))
But how? What in this last chunk of code feeds the ndx
in the first chunk?