r - R 中的并行处理: checkForRemoteErrors(val) 中的错误:7 个节点产生错误;第一个错误:未使用的参数(MARGIN = base::quote(2))
问题描述
我正在尝试使用 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))
我认为我很迷茫,非常感谢任何帮助:)
解决方案
该错误非常明确:
7 nodes produced errors; first error: unused argument (MARGIN = base::quote(2))
/MARGIN
中没有参数。您可能误认为.parSapply()
sapply()
apply()
推荐阅读
- python - 列出的列表返回索引值
- r - 如何根据名称文本将多个变量与 R 中的特定模式合并?
- javascript - 在指针事件为 null 的元素上“单击”(或替代方法)
- mysql - ModuleNotFoundError:导入 mysql 时没有名为“_version”的模块
- c# - 在单击 Xamarin.Forms.Maps 时添加图钉
- r - 在 R 中使用 sapply 而不是循环
- javascript - NextJS React 应用样式的组件渲染不正确:警告:道具`className`不匹配
- python - Python:在使用标准库与使用其他人的包装器之间进行权衡
- arrays - 索引可能不存在(textField)swift xcode
- datepicker - datepicker: (change) 事件或 (selectedChanged) 在 mat-datepicker 中不起作用