I found the book to be an excellent way to get beyond the pages of proofs and theory, to explain Bayes in terms that can easily be related to!
I have a stack of Bayesian books I am citing for my PhD dissertation, and this one sits on the top (which is often unstable since it is larger than Zellner or Albert).
Now, I want to work through every R example, and learn what JAGS can do, which is not actually in my book.
linux boxes may experience the same problem as Macs (which you described in step #2).
For me, using Ubuntu 10.04, it was necessary to use JAGS 2.*. Downloaded the binary from JAGS site, sudo dpkg -i ****.deb, and then a further step was necessary; gksudo synaptic and fix the broken package, because
jags depends on libatlas3gf-base; however: Package libatlas3gf-base is not installed.
I was able to get rjags and JAGS 3 to work on Mac OS X Lion, provided that I compiled JAGS from source. I think that it is necessary to use PIC flags when compiling JAGS so that it works with R (e.g., from MacPorts):
Install R with: port install R +gcc46 +recommended
Is there an up to date information on how to install.
I'm using osx 10.9.2 r version 3.1
Tried the instructions of the above comment.
Warning: namespace ‘rjags’ is not available and has been replaced by .GlobalEnv when processing object ‘LINE’ ** testing if installed package can be loaded Error : .onLoad failed in loadNamespace() for 'rjags', details: call: dyn.load(file, DLLpath = DLLpath, ...) error: unable to load shared object '/Library/Frameworks/R.framework/Versions/3.1/Resources/library/rjags/libs/rjags.so': dlopen(/Library/Frameworks/R.framework/Versions/3.1/Resources/library/rjags/libs/rjags.so, 10): Symbol not found: __ZN5RangeC1ERKNSt3__16vectorIiNS0_9allocatorIiEEEES6_ Referenced from: /Library/Frameworks/R.framework/Versions/3.1/Resources/library/rjags/libs/rjags.so Expected in: flat namespace in /Library/Frameworks/R.framework/Versions/3.1/Resources/library/rjags/libs/rjags.so Error: loading failed Execution halted ERROR: loading failed * removing ‘/Library/Frameworks/R.framework/Versions/3.1/Resources/library/rjags’ Warning in install.packages : installation of package ‘rjags’ had non-zero exit status
Did you see in Step 1: "Mac users: As of May 07, 2014, it seems that rjags (step 4 below) only works for the Snow Leopard build of R3.1.0, not the Mavericks build of R3.1.0. So, use the Snow Leopard build."
I am told that if you use the Snow Leopard build of R, then the ordinary install.packages(rjags) command should work.
Please let me know if you've tried that and it does not work (and do provide details). I will forward your question to the JAGS blog (Martyn Plummer), as I do not use a Mac myself.
At the JAGS discussion/help thread (here), Martyn Plummer said: "I have been in contact with Bill [NorthCott]. It will be June before he is able to make a Mavericks build, I'm afraid, so you will need to be patient. The Snow Leopard build does work on Mavericks so you will need to use this workaround until then. Sorry for the inconvenience."
Hi, I am running R Studio on Mac OSX Version 10.9.3 to input the programmes and do the exercises in the textbook.
When running programmes, R Studio is having trouble sourcing the 'embedded' programmes, such as plotPost.R, which is used in chapter 7, as well as openGraph.R and saveGraph.R. I just get error messages, rather than have them working.
I have followed the instructions to 'point' the default working directory to the folder where these programmes are stored, but I still can't get them to work.
Grateful for somebody giving me an idea of what I've done wrong, and how I can rectify the problem.
And many thanks for the book! What a great, comprehensible and comprehensive intro to Bayesian Data Analysis!
The easiest way to get RStudio (or R) to use the proper working directory is to open RStudio via the file itself. That is, start with RStudio closed, then find the file (i.e., script or program) you want to open. Double-click (or equivalent in MacOS) and open the file in RStudio. When RStudio opens, it knows to use the file's folder as the working directory.
For more details, check out this video: http://youtu.be/eKZoQ1ztzQo at 4:00 minutes and 5:30 minutes.
The above assumes that you have left all the programs together in the same folder. It also assumes that you have unzipped (a.k.a. extracted) the folder after you downloaded it.
Let me know how it goes, and thanks for your interest in the book!
I am having trouble running your scripts using R version 3.1.2. Whenever I try to plot any of the posterior distributions, I get error messages, in particular:
Error in system2("otool", c("-L", shQuote(DSO)), stdout = TRUE) : error in running command sh: otool: command not found
I have reinstalled xQuartz x11 and it still isn't working.
This was working before I updated to R 3.1.2, so I wonder if you have any advice?
Conor: I have not heard anything about that error before. Apparently you are using MacOS? I don't use MacOS, so I must rely on other readers to chime in. Meanwhile, it would help to isolate the problem. What happens when you type, at R's command line,
plot(0,0)
That's just a basic R command, not anything I programmed. If that doesn't work, then something's wrong with your R installation.
Assuming that works, what happens when you type
source("DBDA2E-utilities.R") openGraph()
If that doesn't work, let us know what the error message says.
My guess is that it has something to do with the X11() command. I found this in the "New Features" of R 3.1.2:
"(OS X only.) Package tcltk checks when loaded if it is linked against the CRAN X11-based Tcl/Tk and if so that the Tcl/Tk component and the X11 libraries are installed. This allows more informative error messages to be given advising the installation of the missing component or of XQuartz.
The X11() device and X11-based versions of the data editor and viewer (invoked by edit() and View() for data frames and matrices from command-line R) check that the X11 libraries are installed and if not advises installing XQuartz."
In other words, it seems that the X11() function has been changed for OS-X, and this might be causing the error you are encountering. Perhaps you can get an answer from an online forum such as this one: http://r.789695.n4.nabble.com/tcltk-td4701101.html
I found the book to be an excellent way to get beyond the pages of proofs and theory, to explain Bayes in terms that can easily be related to!
ReplyDeleteI have a stack of Bayesian books I am citing for my PhD dissertation, and this one sits on the top (which is often unstable since it is larger than Zellner or Albert).
Now, I want to work through every R example, and learn what JAGS can do, which is not actually in my book.
linux boxes may experience the same problem as Macs (which you described in step #2).
ReplyDeleteFor me, using Ubuntu 10.04, it was necessary to use JAGS 2.*. Downloaded the binary from JAGS site, sudo dpkg -i ****.deb, and then a further step was necessary; gksudo synaptic and fix the broken package, because
jags depends on libatlas3gf-base; however:
Package libatlas3gf-base is not installed.
Luckily Synaptic took care of the problem.
Thank you for posting these instructions. And thanks for all your other very accessible work on Bayesian stats!
ReplyDeleteI was able to get rjags and JAGS 3 to work on Mac OS X Lion, provided that I compiled JAGS from source. I think that it is necessary to use PIC flags when compiling JAGS so that it works with R (e.g., from MacPorts):
ReplyDeleteInstall R with:
port install R +gcc46 +recommended
Install JAGS from source:
export CC=gcc-mp-4.6 CFLAGS="-fPIC -O2 -g" CXX=g++-mp-4.6 CXXFLAGS="-fPIC -O2 -g" F77=gfortran-mp-4.6 FFLAGS="-fPIC -O2 -g" ./configure --with-pic --prefix=/opt/JAGS-3.2.0
(change prefix to wherever you want to install) and then in my .bashrc
export PATH=/opt/JAGS-3.2.0/bin:{$PATH}
export DYLD_LIBRARY_PATH=/opt/JAGS-3.2.0/lib:${DYLD_LIBRARY_PATH}
Close terminal window, open new window so that .bashrc is sourced. Then you should be able to install rjags with
/opt/local/bin/R
install.packages('rjags', type='source', dependencies=c('Depends','Suggests'))
Can not install rjags
ReplyDeleteIs there an up to date information on how to install.
I'm using osx 10.9.2
r version 3.1
Tried the instructions of the above comment.
Warning: namespace ‘rjags’ is not available and has been replaced
by .GlobalEnv when processing object ‘LINE’
** testing if installed package can be loaded
Error : .onLoad failed in loadNamespace() for 'rjags', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/Library/Frameworks/R.framework/Versions/3.1/Resources/library/rjags/libs/rjags.so':
dlopen(/Library/Frameworks/R.framework/Versions/3.1/Resources/library/rjags/libs/rjags.so, 10): Symbol not found: __ZN5RangeC1ERKNSt3__16vectorIiNS0_9allocatorIiEEEES6_
Referenced from: /Library/Frameworks/R.framework/Versions/3.1/Resources/library/rjags/libs/rjags.so
Expected in: flat namespace
in /Library/Frameworks/R.framework/Versions/3.1/Resources/library/rjags/libs/rjags.so
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/Library/Frameworks/R.framework/Versions/3.1/Resources/library/rjags’
Warning in install.packages :
installation of package ‘rjags’ had non-zero exit status
Dear Can Candan:
ReplyDeleteDid you see in Step 1: "Mac users: As of May 07, 2014, it seems that rjags (step 4 below) only works for the Snow Leopard build of R3.1.0, not the Mavericks build of R3.1.0. So, use the Snow Leopard build."
I am told that if you use the Snow Leopard build of R, then the ordinary install.packages(rjags) command should work.
Please let me know if you've tried that and it does not work (and do provide details). I will forward your question to the JAGS blog (Martyn Plummer), as I do not use a Mac myself.
At the JAGS discussion/help thread (here), Martyn Plummer said: "I have been in contact with Bill [NorthCott]. It will be June before he is able to make a Mavericks build, I'm afraid, so you will need to be patient. The Snow Leopard build does work on Mavericks so you will need to use this workaround until then. Sorry for the inconvenience."
ReplyDeleteThanks Mr John,
ReplyDeleteit works as you have said :)
Hi, I am running R Studio on Mac OSX Version 10.9.3 to input the programmes and do the exercises in the textbook.
ReplyDeleteWhen running programmes, R Studio is having trouble sourcing the 'embedded' programmes, such as plotPost.R, which is used in chapter 7, as well as openGraph.R and saveGraph.R. I just get error messages, rather than have them working.
I have followed the instructions to 'point' the default working directory to the folder where these programmes are stored, but I still can't get them to work.
Grateful for somebody giving me an idea of what I've done wrong, and how I can rectify the problem.
And many thanks for the book! What a great, comprehensible and comprehensive intro to Bayesian Data Analysis!
Dear Jeremy:
ReplyDeleteThe easiest way to get RStudio (or R) to use the proper working directory is to open RStudio via the file itself. That is, start with RStudio closed, then find the file (i.e., script or program) you want to open. Double-click (or equivalent in MacOS) and open the file in RStudio. When RStudio opens, it knows to use the file's folder as the working directory.
For more details, check out this video: http://youtu.be/eKZoQ1ztzQo
at 4:00 minutes and 5:30 minutes.
The above assumes that you have left all the programs together in the same folder. It also assumes that you have unzipped (a.k.a. extracted) the folder after you downloaded it.
Let me know how it goes, and thanks for your interest in the book!
Dear John,
ReplyDeleteI am having trouble running your scripts using R version 3.1.2. Whenever I try to plot any of the posterior distributions, I get error messages, in particular:
Error in system2("otool", c("-L", shQuote(DSO)), stdout = TRUE) :
error in running command
sh: otool: command not found
I have reinstalled xQuartz x11 and it still isn't working.
This was working before I updated to R 3.1.2, so I wonder if you have any advice?
Conor:
ReplyDeleteI have not heard anything about that error before. Apparently you are using MacOS? I don't use MacOS, so I must rely on other readers to chime in. Meanwhile, it would help to isolate the problem. What happens when you type, at R's command line,
plot(0,0)
That's just a basic R command, not anything I programmed. If that doesn't work, then something's wrong with your R installation.
Assuming that works, what happens when you type
source("DBDA2E-utilities.R")
openGraph()
If that doesn't work, let us know what the error message says.
Hi John,
ReplyDeleteThanks for the speedy reply. I am running Mac OS X 10.8.5.
I get the same error message after typing source/openGraph() :
openGraph()
sh: otool: command not found
Error in system2("otool", c("-L", shQuote(DSO)), stdout = TRUE) :
error in running command
Called from: X11(width = width * mag, height = height * mag, type = "cairo",
…)
plot(0 , 0) works fine.
I also tried to run some code relating to time series analyses, in the package RandomFields, and I got the same error message:
library(RandomFields)
Loading required package: sp
sh: otool: command not found
Error : .onLoad failed in loadNamespace() for 'tcltk', details:
call: system2("otool", c("-L", shQuote(DLL)), stdout = TRUE)
error: error in running command
Error: package or namespace load failed for ‘RandomFields’
So this is probably unrelated to Jags/your codes.
Thanks for all your help!
Conor:
ReplyDeleteMy guess is that it has something to do with the X11() command. I found this in the "New Features" of R 3.1.2:
"(OS X only.) Package tcltk checks when loaded if it is linked against the CRAN X11-based Tcl/Tk and if so that the Tcl/Tk component and the X11 libraries are installed. This allows more informative error messages to be given advising the installation of the missing component or of XQuartz.
The X11() device and X11-based versions of the data editor and viewer (invoked by edit() and View() for data frames and matrices from command-line R) check that the X11 libraries are installed and if not advises installing XQuartz."
In other words, it seems that the X11() function has been changed for OS-X, and this might be causing the error you are encountering. Perhaps you can get an answer from an online forum such as this one: http://r.789695.n4.nabble.com/tcltk-td4701101.html
I just found this thread, which appears to provide an answer: https://www.mail-archive.com/r-sig-mac@r-project.org/msg03306.html
ReplyDeleteThanks so much, John. That's very helpful!
ReplyDeleteBetween comments, I downgraded R to the last version I was using (2.15.3) when the scripts were working fine, and that has worked.
I will investigate that blog post more and see if 3.1.2 will work smoothly next time.
Best wishes
Conor