[ad_1]

How to use the boot function in R, if the function that computes the needed statistic has two arguments. Here is the code for the function that computes the statistic:

```
win_sample <- function(sample, alpha) {
n <- length(sample)
r <- floor(n*alpha) + 1
s <- n-floor(n*alpha)
sample.ord <- sort(sample)
sample_win <- c(rep(sample.ord[r], r-1), sample.ord[r:s], rep(sample.ord[s], r-1))
sample_win
}
trimvar <- function(sample, alpha) {
n <- length(sample)
win.sample <- win_sample(sample, alpha = alpha)
trim.sigma <- 1/(n-1)/n/(1-2*alpha)^2 * sum((win.sample-base::mean(win.sample))^2)
trim.sigma
}
trimvar <- Vectorize(FUN = trimvar, vectorize.args = "alpha")
```

Here is what I tried regarding the boot function:

```
bs_var <- function(data, alpha){
boot(data = data, statistic = trimvar(alpha), R = 100)
}
bs_var <- Vectorize(FUN = bs_var, vectorize.args = "alpha")
```

The error I get: `Error in sample.ord[r:s] : only 0's may be mixed with negative subscripts.`

I think it’s something to do with the way the statistic is defined within boot function. If I explicitly write statistic = trimvar(alpha = alpha), then r says that there is no sample argument defined, and if I write `trimvar(sample = sample, alpha = alpha)`

, then the error message is `could not find the function statistic`

, because then it’s not function but a value.

[ad_2]