如何 bootstrap 与 lapply? bootstrap R 中的 boot() 错误

How to bootstrap with lapply? bootstrap error with boot() in R

我在尝试执行下面的代码时遇到错误 "Error in statistic(data, original, ...) : unused argument (original)"。具体来说,我正在尝试为每个 plot# 应用一个函数和 bootstrap 这些结果。我是不是漏掉了什么直截了当的东西?

    library(codyn) # has sample dataset called pplots
    library(boot)

    str(pplots)

    stability <- function(x){
  mean(multivariate_change(x,
                           species.var = "species",
                           time.var = "year",
                           abundance.var = "relative_cover",
                           replicate.var = "plot")$composition_change)
}

boot_obj <- lapply(splitspplots,boot,statistic = stability,R = 20)
boot_obj <- lapply(splitspplots,myBootFun)

myBootFun <- function(x,i) {
  lapply(x[i],boot, statistic=stability, R = 10)
}
myBootFun <- function(x,i) {
  boot(x[i], statistic=stability, R = 10)
}
splitspplots <- split(pplots,pplots$plot)
lapply(splitspplots, print(myBootFun))

我想到了一种同样有效的不同方法。

我使用了一个 for 循环来遍历不同的 groups/sites,但我没有在这里显示。这是 bootstrap 代码。

data_sampled <- data_grouped %>%
    group_by(SITE_ID) %>%
    crossing(id = seq(100)) %>% # create replicate dataframes
    sample_n(size = n(), replace = T) # sample dataframes