找不到“mixstock”包中的“calc.RL.0”函数。

huangapple go评论49阅读模式
英文:

Cannot not find "calc.RL.0" function within "mixstock" package

问题

我试图在RStudio中运行基于Bolker提供的教程(https://citeseerx.ist.psu.edu/document?repid=rep1&type=pdf&doi=043730a02b148396ebd54b2f62e8f6364714b1b2)的混合股票分析,使用‘mixstock’包和示例数据集‘lahanas98raw’。然而,我收到了一个警告,即在进行Raftery和Lewis收敛诊断(Bolker教程的第14页)时找不到‘calc.RL.0’函数。我在想是不是其中一个包没有正确安装(即‘mixstock’或‘coda’),或者是否有另一个包可以用来运行这个诊断。

当我最初尝试安装‘mixstock’包时,出现了以下警告:
‘在install.packages中的警告:此版本的R不适用于包‘mixstock’。’
我尝试安装Bolker教程第2页描述的R版本(2.14.1)作为‘当前版本的R’,但当我尝试在RStudio中通过选项菜单切换到此版本的R时,它显示此版本的R与RStudio不兼容。为了解决这个问题,我从CRAN存档(https://cran.r-project.org/src/contrib/Archive/mixstock/)下载了‘mixstock’包(版本0.9.5.1),然后将其上传到RStudio中。

这似乎起到了作用,因为我成功地运行了大量代码,但在我尝试运行Raftery和Lewis收敛诊断时(第14页),出现了一个新的错误。当我尝试运行calc.RL.0(mydata)时,我收到以下错误:
‘在calc.RL.0(mydata)中的错误:找不到函数“calc.RL.0”。’
然而,当我在包窗口中点击‘mixstock’时,一切都看起来很正常,‘calc.RL.0’函数出现在其中,还有几个其他的‘calc’函数(例如‘calc.GR’、‘calc.mult.GR’、‘calc.mult.RL’),它们都可以找到并且可以正常运行。‘calc.RL.0’函数依赖于‘coda’包中的‘raftery.diag’函数,所以我也确保它已安装并被调用。我尝试了许多其他方法,但似乎没有任何效果。

以下是在警告消息之前的一些我的代码:

## 计算置信区间 - 即自助法 - 并绘制它们
mydata.umlboot = genboot(mydata, "uml")
confint(mydata.umlboot)
plot(mydata.umlboot, ylim=c(0,1))

## 进行马尔科夫链蒙特卡洛(MCMC)估计并绘制它们
mydata.mcmc = tmcmc(mydata)
mydata.mcmc
confint(mydata.mcmc)
plot(mydata.mcmc, ylim=c(0,1))

## 检查马尔科夫链是否收敛 = 运行Raftery和Lewis诊断
library(mixstock)
library(coda)
calc.RL.0(mydata)
    '在calc.RL.0(mydata)中的错误:找不到函数“calc.RL.0”'

这可能与最初安装‘mixstock’包的方式有关,或者可能是另一个问题。是否有另一种方法可以运行Raftery和Lewis诊断,并获得我需要的输出(对最后评估的链的诊断;每个建议链的历史持续时间)?对任何帮助我都将不胜感激 - 提前感谢!

英文:

I am trying to run through a mixed stock analysis in RStudio based on the walkthrough provided by Bolker (https://citeseerx.ist.psu.edu/document?repid=rep1&type=pdf&doi=043730a02b148396ebd54b2f62e8f6364714b1b2), using the 'mixstock' package and the example 'lahanas98raw' dataset within. However, I am receiving a warning that the 'calc.RL.0' function cannot be found whilst trying to carry out Raftery and Lewis convergence diagnostics (p.14 of Bolker's walkthrough). I am wondering whether one of the packages has not installed properly (i.e., either 'mixstock' or 'coda'), or whether there is another package I can use to run this diagnostic instead.

When I initially tried to install the 'mixstock' package, the following warning came up:
'Warning in install.packages : package ‘mixstock’ is not available for this version of R.'
I tried installing the version of R (2.14.1) described as the 'current version of R' on page 2 of Bolker's walkthrough, but when I then tried to switch to this version of R in RStudio via the options menu, it says that this version of R is not compatible with RStudio. To work around this, I downloaded the 'mixstock' package (version 0.9.5.1) from the CRAN archive (https://cran.r-project.org/src/contrib/Archive/mixstock/) and uploaded it to RStudio this way instead.

This seemed to have worked, as I successfully ran through a significant amount of the code, but a new error arose when I tried to run Raftery and Lewis convergence diagnostics (p.14). When I try to run calc.RL.0(mydata), I receive the following error:
'Error in calc.RL.0(mydata) : could not find function "calc.RL.0"'
However, when I click on 'mixstock' in the package window, everything seems fine and the 'calc.RL.0' function appears, alongside several other 'calc' functions (e.g. 'calc.GR', 'calc.mult.GR', 'calc.mult.RL') that can all be found and run fine. The 'calc.RL.0' function relies on the 'raftery.diag' function within the 'coda' package, so I have also made sure that is installed and called. I have tried a bunch of other methods but nothing seems to be working.

Here is some of my code leading up to the warning message:

## Calculate confidence intervals - i.e., bootstrapping - and plot them
mydata.umlboot = genboot(mydata,"uml")
confint(mydata.umlboot)
plot(mydata.umlboot, ylim=c(0,1))

## Carry out Markov Chain Monte Carlo (MCMC) estimations and plot them
mydata.mcmc = tmcmc(mydata)
mydata.mcmc
confint(mydata.mcmc)
plot(mydata.mcmc, ylim=c(0,1))

## Check that the Markov chains have converged = run Raftery and Lewis diagnostics
library(mixstock)
library(coda)
calc.RL.0(mydata)
    'Error in calc.RL.0(mydata) : could not find function "calc.RL.0"'

Could this be something to do with the way the 'mixstock' package was initially installed, or is it likely to be another issue? Is there another way to run Raftery and Lewis diagnostics and still get the outputs I need (diagnostics for the last chain evaluated; the history of how long each suggested chain was)? Any help would be much appreciated - thanks in advance!

答案1

得分: 0

安装 mixstock 的最可靠方法,如果您的计算机已安装开发工具(编译器等),是使用 remotes::install_github("bbolker/mixstock")(我不认为我已更改任何内容/修复任何错误,自存档版本以来,但如果我做出了更改,这些更改将在 GitHub 上反映出来)。

看起来我忘记导出该函数,所以

mixstock:::calc.RL.0(mydata)

应该可行(这是我可以/应该修复的问题)。请注意,Gelman-Rubin 诊断 (calc.GR()),它是正确导出的,比 Raftery-Lewis 更可靠...

英文:

The most reliable way to install mixstock, if you have development tools installed on your computer (compilers etc.), is remotes::install_github("bbolker/mixstock") (I don't think I've changed anything/fixed any bugs since the archived version, but if I did the changes would be reflected on GitHub.)

It looks like I forgot to export that function, so

mixstock:::calc.RL.0(mydata)

should work (this is something I can/should fix). Note that the Gelman-Rubin diagnostic (calc.GR(), which is properly exported) is more reliable than Raftery-Lewis anyway ...

huangapple
  • 本文由 发表于 2023年2月14日 02:21:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/75439815.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定