Software, with programs for book
Complete steps for installing software and programs:
Install the general programming language R. Go to the R web site and install the latest version of R appropriate for your computer (Windows, Mac, Linux). Mac users: You need to use compatible versions of R and JAGS, depending on what version of MacOS you are using. Please see the JAGS web sites, https://martynplummer.wordpress.com/category/mac-os-x/ and http://sourceforge.net/p/mcmc-jags/discussion/610037/thread/42a11070/ for complete info.
Install the R editor RStudio. R comes with its own built-in editor, but it is not very useful for dealing with long programs. Go to the RStudio web site and install the latest version of RStudio appropriate for your computer (Windows, Mac, Linux).
Install the Bayesian sampling program JAGS. Go to the JAGS web site and install the latest version of JAGS appropriate for your computer (Windows, Mac, Linux). Mac users: See note in step 1 about using compatible versions of R and JAGS. The JAGS blog is at https://martynplummer.wordpress.com/.
Install the packages that let R talk to JAGS. Actually, you can skip this step if you are using the programs from DBDA2E, because they will automatically install rjags and runjags. But if you want to do it manually, here's how: Invoke RStudio. Click the "Tools" menu and then "Install Packages." In the Packages slot type "rjags" without the quotes, or, if a menu of packages appears, select rjags. Then click install. (Alternatively, if working in R not RStudio, at the command line, type install.packages("rjags") You may be prompted to select an internet archive to get the package from; select a site geographically near you.) Also install the package "runjags" using same procedure.
Get the programs used in the book. A zip file named DBDA2Eprograms.zip contains all the programs and data files. Get it from the files listed at the bottom of this page. Save the zip file where you would save ordinary user files, not in protected directory such as Windows Program Files. Be sure to unzip (extract) the programs from the zip file. For programs for the 1st Edition, click the 1st Edition link in the left margin. Mac users: R opens graphics windows using the standard X11 library, which is no longer part of the standard MacOS. When you try running programs that open a graphics window, you will get a message: "Error in check_for_XQuartz(): X11 library is missing: install XQuartz from xquartz.macosforge.org". Please install XQuartz as instructed. You will have to restart your session, but then the graphics should work. One other Mac issue: The Greek symbol fonts used by R do not display properly on a Mac. If you have found a solution to the font problem, please contact the author (see contact link in the left margin). You will not encounter these issues if you are using MS Windows.
Check that all the above is working properly, as follows:
First, if you already have RStudio or R open, exit from or quit both!
Open the folder of programs from the book, DBDA2Eprograms (from step 5). Find the file Jags-ExampleScript.R, and double-click it. When your computer asks what application to use to open the file, specify RStudio (not R). RStudio will open with the file Jags-ExampleScript.R displayed in its upper left editing pane.
Click anywhere in that editing pane to activate that pane and put the cursor there. Select all the lines using ctrl-A (in Windows, or cmd-A in MacOS). Then run all the lines by pressing ctrl-Enter (in Windows) or by clicking the button marked "Run" at the top edge of the pane.
While running, if you did not manually install the packages the let R talk to JAGS (Step 4), the program will attempt to do this for you. Your computer must be connected to the internet.
The program will attempt to open new graphics windows and display plots. (On a Mac, you might get an error message about X11 or XQuartz. As mentioned in Step 5, please install XQuartz onto your Mac, and, after installing, have XQuartz running in the background. Quit RStudio then re-open Jags-ExampleScript.R and run it again.) If you get graphs displayed, you have successfully installed the software. If not, please carefully go through all the steps again.
7. If you will be using Stan, install Stan by following the instructions at the RStan web site. Then go to R and install the RStan package. Stan is not needed for the JAGS programs.
8. Read the important tips for running the programs, below! Really, read them. Remember them. It will save you frustration later.
Important tips for running the programs:
• Many of the programs call other programs and write auxiliary files, so
• put all the programs together in the same folder (they come together in one folder, so it's easiest to leave them there),
• put that folder under a writeable directory (not in a protected system folder), such as where you would store ordinary research data, and
• be sure that R has that folder as its working directory. Set the working directory in RStudio from the menu: Session -> Set Working Dir. Or, if you're using R's built-in editor, set the working directory in R's command console from the menu: File -> Change dir...Without setting the folder as R's working directory, you will get errors when programs try to find other files and can't find them.
• Programs may be updated occasionally. Check back here for updates.