【问题标题】:Parallel processing in R : Error in checkForRemoteErrors(val) : 7 nodes produced errors; first error: unused argument (MARGIN = base::quote(2))R 中的并行处理: checkForRemoteErrors(val) 中的错误:7 个节点产生错误;第一个错误:未使用的参数(MARGIN = base::quote(2))
【发布时间】:2020-09-27 09:08:05
【问题描述】:

我正在尝试使用 apply 系列函数和以下代码行进行并行计算。 目标是使 silum_ 矩阵的每一列都适合我的规范以及当我检查时

dim((simul_[,1]))

我得到“NULL”,这导致应用函数出现问题。 完整代码如下:

## Library
lib_vec = c("MSGARCH", "matrixStats", "parallel")
invisible(lapply(lib_vec, f_install_load_lib)) 

## seed
set.seed(1234)

MSGARCH 包中的 MSGARCH 模型规范

MSGARCH_spec <- CreateSpec(variance.spec = list(model = c("sGARCH", "sGARCH")),
                            distribution.spec = list(distribution = c("norm",
                                                                      "norm")),
                            switch.spec = list(do.mix = FALSE, K = NULL),
                            constraint.spec = list(fixed = list(), 
                                                   regime.const = NULL),
                            prior = list(mean = list(), sd = list()))

MSGARCH 拟合:sp500_logrets 只是日志返回。

MSgarch_fit <- FitML(data = sp500_logrets, spec = MSGARCH_spec)

模拟 MSGARCH Log_returns

nsim <- 100 # number of simulations
nahead <- 1000 # size of each simualtion
MS_simul <- simulate(MSgarch_fit, nsim = nsim, nahead = nahead, n.start = 500, 
                     nburn = 100)
simul_ <- MS_simul$draw # retrieving the simulated data


并行计算设置

n_cores <- detectCores()
cl <- makeCluster(n_cores[1] - 1)

通过应用函数的并行计算拟合每个模拟

fitt_ <- parSapply(cl, X = simul_, MARGIN = 2, FUN = FitML, spec = MSGARCH_spec)

stopCluster(cl)

我得到的错误是:

7 nodes produced errors; first error: unused argument (MARGIN = base::quote(2))

我认为 我很迷茫,非常感谢任何帮助:)

【问题讨论】:

  • 这是一个警告,不一定是错误。如果你多次尝试,你确定每次都跑stopCluster
  • 是的,我确实运行了 stopCluster。在警告之后,有一条错误消息。

标签: r parallel-processing


【解决方案1】:

错误非常明确:

7 nodes produced errors; first error: unused argument (MARGIN = base::quote(2))

parSapply()/sapply() 中没有参数MARGIN。 您可能误认为apply()

【讨论】:

  • 这次我使用了parApply函数,以便可以使用margin参数。如果您从 sp500_logrets 的正态分布生成数据集,我认为我的代码是可重现的。我认为错误也可能是未预先分配的 fitt_ 但我不知道该怎么做。请帮忙——
  • 每次解决前一个错误时,您都无法更新收到的错误。请关闭此问题并打开一个新问题。对于您的新错误,您可能需要先搜索,因为它可能已经得到了回答。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-26
  • 2016-08-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多