mikemeredith / AHM_code

Code from the book 'Applied Hierarchical Modeling in Ecology'
37 stars 18 forks source link

Error message for updated JagsUI/Coda MCMC object specification: Error in mcmc.list(x) : Arguments must be mcmc objects #1

Closed Jrogan23 closed 3 years ago

Jrogan23 commented 3 years ago

Thank you for reporting a bug in our scripts.

The code here is based on the book, and we update it to work with current versions of JAGS, R and R packages. Please make sure you have the latest version of the script and software (run update.packages()) before reporting an issue.

File name: AHM1_ch11

Lines which produced the error or unexpected output (copy/paste from the console): op <- par(mfrow = c(4,4)) ; traceplot(out5) ; print(out5, dig = 3)

error message: Error in mcmc.list(x) : Arguments must be mcmc objects

Do you have a suggested update for the code:

Coda specifies that in the updated version, older mcmc objects will result in an error message. "n previous releases of CODA, an mcmc object could be a single or multiple chains. A new class mcmc.list has now been introduced to deal with multiple chains and mcmc objects can only have data from a single chain."

mcmcUpgrade(x) can be used to update outdated code for mcmc objects; or objects could be modified to specified correctly under the updated version of the coda package

Run sessionInfo() and paste the output here:

R version 4.0.3 (2020-10-10) Platform: x86_64-apple-darwin17.0 (64-bit) Running under: macOS Catalina 10.15.6

Matrix products: default BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] AHMbook_0.2.0 coda_0.19-4 jagsUI_1.5.1 lattice_0.20-41

loaded via a namespace (and not attached): [1] Rcpp_1.0.5 mvtnorm_1.1-1 codetools_0.2-16 unmarked_1.0.1
[5] MASS_7.3-53 grid_4.0.3 plyr_1.8.6 RandomFields_3.3.8
[9] raster_3.3-13 sp_1.4-4 rjags_4-10 RColorBrewer_1.1-2
[13] tools_4.0.3 plotrix_3.7-8 parallel_4.0.3 compiler_4.0.3
[17] RandomFieldsUtils_0.5.3

Other information that may be helpful to pinpoint the issue, eg, screenshots:

mikemeredith commented 3 years ago

The error arises because you loaded package coda after loading jagsUI, which is clear from your sessionInfo output. When you did that, you should have seen a message:

The following object is masked from ‘package:jagsUI’:
    traceplot

So when you do traceplot(out5) you are calling coda::traceplot, not jagsUI::traceplot. And, yes, that only works with valid mcmc objects, while out5 is class jagsUI.

There's no call to library(coda) in the script, so it's not a bug. On the other hand it is called in 11.07, so maybe good to specify jagsUI::traceplot everywhere in chapter 11.

mikemeredith commented 3 years ago

The library(coda) call in 11.07 is unnecessary, so I have removed it (commented it out).

Jrogan23 commented 3 years ago

Sorry for the confusion, and thanks for helping out with this!

On Mon, Oct 26, 2020 at 4:50 AM mikemeredith notifications@github.com wrote:

The library(coda) call in 11.07 is unnecessary, so I have removed it (commented it out).

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/mikemeredith/AHM_code/issues/1#issuecomment-716436343, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOT5HDRK7VVHAHA6DWZ2JVDSMVA7DANCNFSM4S4YUZNQ .

-- Jordan Rogan

Ph.D. Candidate, Applied Biodiversity Sciences Department of Ecology and Conservation Biology (ECCB) Texas A&M University Website: jordanrogan.wordpress.com | Twitter: @jordrogan | Skype: jord0123