# 21 August 2020 ###################################################### #Installation Instructions for the Scholar Cluster ###################################################### 1. Log in to the Remote Desktop here: https://desktop.scholar.rcac.purdue.edu:300/main/ 2. Click 'Applications' at top left. On drop-down menu, select 'Terminal emulator'. 3. Type the following, pressing your return/enter key at the end of each line. (Note: Do not type the leading dollar signs; they will already be in the terminal and preceded by: yourUserName@scholar - fe05:~) $ mkdir -p $HOME/Rlibs $ module load rstudio $ module load r/3.6.3 $ module load libv8 $ export R_LIBS=$HOME/Rlibs $ rstudio 4. RStudio should now be open. Do not close Terminal. In Console, run this: > Sys.setenv(MAKEFLAGS = "-j5") > install.packages("rstan",type="source") After this is finished, you should see rstan in your list of packages on the bottom right pane of RStudio. If not, it did not install properly, and you should contact me. 5. Close RStudio. In the same Terminal window, again type: $ rstudio 6. RStudio should be open again. In Console, run this: > Sys.setenv(MAKEFLAGS = "-j5") > install.packages(c("coda","mvtnorm","devtools","dagitty")) > library(devtools) > devtools::install_github("rmcelreath/rethinking") #At the prompt, press 1 to update all. 7. Make sure it works, and learn how to upload files to the Scholar Remote Desktop. 7a. Uploading files to the remote desktop. There are two ways to do this that are relatively easy. (i) Use the Scholar jupyter hub here: https://notebook.scholar.rcac.purdue.edu/ (ii) Use the Firefox browser in your Remote Desktop (also in the drop-down menu under 'Applications'->'Internet') to download files from, e.g., the course website, your email account. 7b. Test it! (Even if rethinking and rstan are installed, you may get an error when trying to use them.) Using RStudio, test it with some code from https://github.com/rmcelreath/rethinking (If you do not want to type all this, upload this file to Scholar, and then copy and paste this.) Here is the code to enter into RStudio: library(rethinking) # prep data data( UCBadmit ) UCBadmit$male <- as.integer(UCBadmit$applicant.gender=="male") UCBadmit$dept <- rep( 1:6 , each=2 ) UCBadmit$applicant.gender <- NULL # varying intercepts model m_glmm1 <- ulam( alist( admit ~ binomial(applications,p), logit(p) <- a[dept] + b*male, a[dept] ~ normal( abar , sigma ), abar ~ normal( 0 , 4 ), sigma ~ half_normal(0,1), b ~ normal(0,1) ), data=UCBadmit ) summary(m_glmm1) #If you get a fatal error, restart RStudio and try running the example again. ********************************************************************* IF YOU HAVE INSTALLED ALL THE PACKAGES SUCCESSFULLY, BUT THE PACKAGES CANNOT BE LOCATED ONCE YOU OPEN RSTUDIO, DO NOT REINSTALL THEM. _THE PROBLEM_ If you close Terminal, the path to your packages is reset to the default one. Plus, in Linux, the package V8 (or libv8), which is used to compile rstan, must be loaded via the terminal. _WHAT TO DO ABOUT IT_ If this terminal becomes closed (you might not do it, but a system reset may be performed weekly on Saturday nights on Scholar that will kill all process and close all windows), do the following before opening RStudio: In a terminal type: $ module load rstudio $ module load libv8 $ export R_LIBS=$HOME/Rlibs $ rstudio If you do not want to type these 4 lines every time you open a new terminal, one option is to make a bash script that does this for you. To do so: 1. Open Terminal. 2. To make it easier, make sure you are in your home directory. (Every time you open terminal, you start at your home directory by default.) If you are not sure, enter $ pwd and you should see: /home/yourUserName 3. To create a file and open it, in terminal enter: $ touch rstudioStart.sh $ nano rstudioStart.sh 4. Type the following 5 lines (via GNU nano): #!/bin/sh module load rstudio module load libv8 export R_LIBS=$HOME/Rlibs rstudio 5. Press Control-O to save this as the content of the file. 6. Press Control-X to exit. 7. You should be back in Terminal. Now, anytime you open a terminal, you just need to type the following command to open RStudio with all the right settings for rstan: $ bash rstudioStart.sh ********************************************************************* ###################################################### #Installation Instructions for macOS Mojave 10.14.6 ###################################################### Straightforward using RStudio 1.3.959 with R 4.0.2. 1. In the Packages panel of RStudio, click Install and search for rstan. Make sure 'Install dependencies' is checked, and click Install. 2. Answer 'Yes' to 'Do you want to install from sources the package which needs compilation?' Sit back and enjoy the warning messages... 3. Restart RStudio. 4. Install rethinking by entering the following into Console: > install.packages(c("coda","mvtnorm","devtools","dagitty")) > library(devtools) > devtools::install_github("rmcelreath/rethinking") #At the prompt, press 1 to update all. 5. Restart RStudio (otherwise, may get a fatal error). 6. Test it. Enter this code into rStudio: library(rethinking) # prep data data( UCBadmit ) UCBadmit$male <- as.integer(UCBadmit$applicant.gender=="male") UCBadmit$dept <- rep( 1:6 , each=2 ) UCBadmit$applicant.gender <- NULL # varying intercepts model m_glmm1 <- ulam( alist( admit ~ binomial(applications,p), logit(p) <- a[dept] + b*male, a[dept] ~ normal( abar , sigma ), abar ~ normal( 0 , 4 ), sigma ~ half_normal(0,1), b ~ normal(0,1) ), data=UCBadmit ) summary(m_glmm1) ###################################################### #Installation Instructions for macOS Catalina 10.15.6 ###################################################### RStudio 1.2.1335 with R 4.0.2 Works - same instructions as for Mojave above, but no restart needed. ###################################################### #Installation Instructions for Windows 10 version 2004 ###################################################### Using RStudio 1.3.1073 with R 4.0.2. 1. If you did not install Rtools after you installed R binaries ('base'), do so from here: www.r-project.org -> cran -> choose a mirror -> Download R for Windows -> Rtools WARNING: Do not install Rtools via rStudio. (If you try to install rstan via rStudio without having Rtools, rStudio may ask if it can Rtools for you. Just say no, and following the instructions above.) 2. In the Packages panel of RStudio, click Install and search for rstan. Make sure 'Install dependencies' is checked, and click Install. 3. Install rethinking as for macOS Catalina with one change: if you are promted to update packages, do not do so (enter 3). (Updating to backports 1.1.8 resulted in an error for me.) NOTE: Running a rStan via rethinking commands may result in a Warning message: In system(paste(CXX, ARGS)), ignore.stout = TRUE, ignore.stderr = TRUE : '-E' not found I do not know what this means, but this does not appear to impact the output: the output is quite similar to that after running the code in Linux and macOS systems. ###################################################### ###################################################### #Tips and Troubleshooting ###################################################### ###################################################### The current version of rstan (2.21.2) and/or rethinking (2.12) does not seem compatible with: -Linux (version on Scholar) with R 4.0.2 or R 4.0.0 -macOS (version Greg uses) with R 4.0.2 To install packages and run scripts faster in R, you can make use of all your cores by entering this first: > Sys.setenv(MAKEFLAGS = "-j4") #where 4 is the number of cores that will be used; change it according to your machine's hardware and how much of these resources you would like to let R use. #The Scholar cluster has 24 cores, but your process can by killed by the system if you use too many resources. If you are having trouble installing rstan on your machine or if you get a fatal error when you try to use rethinking, try downgrading R to version 3.6.3 and repeating the installation process. Before trying to reinstall rstan, run the following and restart R/RStudio: > remove.packages("rstan") > remove.packages("StanHeaders") > if (file.exists(".RData")) file.remove(".RData") If you are using Linux and still have issues, something like the Scholar instructions above might work for you. See also: https://github.com/stan-dev/rstan/wiki/Installing-RStan-on-Linux ###################################################### ######################################################