(R) 功能:未找到对象:环境深度是否良好?

(R) 功能:未找到对象:环境深度是否良好?,r,function,object,R,Function,Object,我被一个函数错误弄糊涂了&希望能有一些见解 该函数非常简单,使用gbm.step和其他gbm自动执行增强回归树中涉及的多个过程 "gbm.auto" <- function (grids, samples, 3 parameters) { 每个参数组合循环运行2个BRT,为每个循环生成并迭代更新“最佳”BRT,添加到计数器。大量使用样本 }}} 关闭循环,当第一个}仍然打开时,函数继续。 下一个BRT无法找到样本,即使它与成功使用它的预循环处理作业处于相同的环境深度(1?)。此外,添加

我被一个函数错误弄糊涂了&希望能有一些见解

该函数非常简单,使用
gbm.step
和其他
gbm
自动执行增强回归树中涉及的多个过程

"gbm.auto" <- function (grids, samples, 3 parameters) {
每个参数组合循环运行2个BRT,为每个循环生成并迭代更新“最佳”BRT,添加到计数器。大量使用
样本

}}}
关闭循环,当第一个
}
仍然打开时,函数继续。
下一个BRT无法找到样本,即使它与成功使用它的预循环处理作业处于相同的环境深度(1?)。此外,添加
“globalSamples您需要创建一个最小值,我们可以运行它来查看问题是否存在。您的描述不够精确,无法清楚地了解发生了什么。请发布您收到的确切错误消息。谢谢各位,明天上午我们会做。
}}}
Error in eval(expr, envir, enclos) : object 'samples' not found
"gbm.auto" <-
  function (samples, expvar, resvar, tc, lr, bf)
    { # open function

    require(gbm)
    require(dismo)

    # create binary (0/1) response variable, for bernoulli BRTs
samples$brv <- ifelse(samples[resvar] > 0, 1, 0)
brvcol <- which(colnames(samples)=="brv") # brv column number for BRT

for(j in tc){   # permutations of tree complexity
 for(k in lr){   # permutations of learning rate
  for(l in bf){   # permutations of bag fraction

Bin_Best_Model<- gbm.step(data=samples,gbm.x = expvar, gbm.y = brvcol, family = "bernoulli", tree.complexity = j, learning.rate = k, bag.fraction = l)
}}}        # close loops, producing all BRT/GBM objects & continue through model selection

Bin_Best_Simp_Check <- gbm.simplify(Bin_Best_Model) # simplify model

# if best number of variables to remove isn't 0 (i.e. it's worth simplifying), re-run the best model (Bin_Best_Model, using gbm.call to get its values)
# with just-calculated best number of variables to remove, removed. gbm.x asks which number of drops has the minimum mean (lowest point on the line)
# & that calls up the list of predictor variables with those removed, from $pred.list
if(min(Bin_Best_Simp_Check$deviance.summary$mean) < 0)
  assign("Bin_Best_Simp", gbm.step(data = samples,
                                 gbm.x = Bin_Best_Simp_Check$pred.list[[which.min(Bin_Best_Simp_Check$deviance.summary$mean)]],
                                 gbm.y = brvcol, family = "bernoulli", tree.complexity = j, learning.rate = k, bag.fraction = l))
}
Error in var(cv.cor.stats, use = "complete.obs") : 
  no complete element pairs 
    In cor(y_i, u_i) : the standard deviation is zero