![](/img/trans.png)
[英]Attempting to run a negative binomial regression using the MASS package in R
[英]Negative binomial regression in R using brm causing error when using multiple cores
我正在使用來自brms
package 的brm
function 計算負二項式回歸。 由於這需要相當長的時間,我想按照文檔中的建議使用多個內核。
bfit_s <- brm(
dep_var ~ ind_var +
var1 +
var2 +
(1 | some_level1) + (1 | some_level2),
data = my_df,
family = negbinomial(link = "log", link_shape = "log"),
cores = 4,
control = list(adapt_delta = 0.999)
)
但是,我遇到了一個錯誤,說所有四個工作人員的連接都失敗了:
Compiling the C++ model
Start sampling
starting worker pid=11603 on localhost:11447 at 14:13:56.193
starting worker pid=11601 on localhost:11447 at 14:13:56.193
starting worker pid=11602 on localhost:11447 at 14:13:56.198
starting worker pid=11604 on localhost:11447 at 14:13:56.201
Error in unserialize(node$con) : error reading from connection
Calls: <Anonymous> -> slaveLoop -> makeSOCKmaster
Error in unserialize(node$con) : error reading from connection
Calls: <Anonymous> -> slaveLoop -> makeSOCKmaster
Error in unserialize(node$con) : error reading from connection
Calls: <Anonymous> -> slaveLoop -> makeSOCKmaster
Execution halted
Execution halted
Execution halted
Error in unserialize(node$con) : error reading from connection
Calls: <Anonymous> -> slaveLoop -> makeSOCKmaster
Execution halted
回溯顯示Error in makePSOCKcluster(names = spec, ...): Cluster setup failed. 4 of 4 workers failed to connect.
Error in makePSOCKcluster(names = spec, ...): Cluster setup failed. 4 of 4 workers failed to connect.
我試圖理解這個問題,閱讀了一些關於 SO 這樣的問題,但無法弄清楚為什么我無法連接。 我正在使用 macOS Mojave,問題不在於我嘗試使用比可能更多的內核。 關於如何讓它在多個核心上運行的任何建議?
編輯:正如 sjp 在他的回答中指出的那樣,RStudio 存在問題。 我想我在我的問題中分享了解決問題的代碼,所以每個偶然發現的人都可以解決這個問題,而無需進一步點擊(和閱讀)。
問題是來自 R-4.0.0 的parallel
package。 - 但是這個stan 論壇的用戶提供了一種解決方法。 如果您可以像這樣使用setup_strategy="sequential"
初始化集群:
cl <- parallel::makeCluster(2, setup_strategy = "sequential")
您可以在~/.Rprofile
中添加一個簡短的片段來使這種默認設置:
## WORKAROUND: https://github.com/rstudio/rstudio/issues/6692
## Revert to 'sequential' setup of PSOCK cluster in RStudio Console on macOS and R 4.0.0
if (Sys.getenv("RSTUDIO") == "1" && !nzchar(Sys.getenv("RSTUDIO_TERM")) &&
Sys.info()["sysname"] == "Darwin" && getRversion() == "4.0.0") {
parallel:::setDefaultClusterOptions(setup_strategy = "sequential")
}
這是一個與 RStudio 相關的已知問題。 查看 Stan 論壇和 Github 上的這些相關帖子。
Github: https://github.com/rstudio/rstudio/issues/6692
斯坦論壇: https://discourse.mc-stan.org/t/r-4-0-0-and-cran-macos-binaries/13989/13
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.