0

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?

StupidWolf
  • 45,075
  • 17
  • 40
  • 72
Antoni Parellada
  • 4,253
  • 6
  • 49
  • 114
  • `xor(a,TRUE)` is logically equivalent to `!a` – karakfa Feb 05 '16 at 14:42
  • I thought so. And where does the `ndx` part comes from? – Antoni Parellada Feb 05 '16 at 14:43
  • isn't it the second argument of the function? I think the name of the function is specified in the statistic attribute of boot, which it internally resolves and calls with the corresponding arguments. – karakfa Feb 05 '16 at 15:02
  • Thank you for your help. So the `foo` function "supplies" the arguments that `indicator` needs: `x` (in this case `dat`), and `ndx`. I see where `x` comes from: `dat`, but I can't see where `ndx` originates, or what role it plays in `indicator`. – Antoni Parellada Feb 05 '16 at 17:13
  • 1
    My guess It's a dynamic dispatch, sorry but I have no further info. – karakfa Feb 05 '16 at 19:21

0 Answers0