Create Environment in R with Stan packages (4 cores, 15 Gbytes)
Remix this to get started with R.
R.version.string
Objective
The International Year of the Salmon involves projects that require collaboration on analyses by people all over the world. They need an R environment for really, really easy collaboration ... easier than GitHub (sorry about that) and more like Google Docs and Google Sheets. As in simultaneous. As in "I'm having enough trouble moving from Excel to R, so don't make me learn anything else right now, OK? Yes, thank you, I know it's 2019 not 1989, stop saying that."
Plus that R environment has to be protected from breaking as each of about a hundred pieces of Open Source software is updated or is not updated. So the analysis projects have to be in "containers" like Docker (see rocker). But if you think salmon biologists will not be freaked out by "containers in the cloud" then you haven't met one. So that aspect of the R environment has to be something you can ignore and be successful.
So ... ?
So here we are in Nextjournal, and
- cloud-based -- so we are all on the same page (literally, figuratively, and virtually all at the same time!) and not subject to the idiosyncracies of my laptop in Nanaimo (Canada) compared to yours in Vladivostok (Russia) compared to hers in Bergen (Norway). So we are in the cloud -- not just because this is 2019 instead of 1989 -- to allow proper sharing.
- collaborative -- you can improve my stuff (my notebooks), easy-peasy. For which I will be grateful and honored. And then improve your improvement (take that!) Or re-purpose my stuff (fork, "re-mix")to re-purpose it for your new analysis. My bricks in your cathedral. Our cathedral. Of knowledge.
- contained -- and I finally get to the point. This notebook creates an R environment called R_rstan that is (a) more powerful than the default, with 15 Gybtes of random access memory instead of three and with four virtual cores for processing instead of one, and (b) contains the the Stan packages for rigorous (as in publishable) application of models to data. Competing models. Ecological detectives. Suspects, evidence, challenges, predictions, decisions.
- Ta-dah! -- rigorous, reproducible, collaborative research. And easy-peasy. More publications, more collaborators, more progress.
Stan language and associated R packages.
See Rstan Getting Started https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started
See Rstan The R Interface to Stan https://mc-stan.org/users/interfaces/rstan.html
The following packages provide the complete environment for Stan users. Date: 2019-07-02. Most of these are "required" by package rstan so do not require separate installation.
- rstan - https://mc-stan.org/users/interfaces/rstan.html - the R interface to Stan.
- rstanarm - https://mc-stan.org/users/interfaces/rstanarm.html - useful precompiled models.
- brms - https://mc-stan.org/users/interfaces/brms.html - automate regression modeling (compile on the fly), slightly different classes of models and automated posterior analyses that rstanarm.
- shinystan - http://mc-stan.org/shinystan - interactive visual summaries and advanced posterior analysis of MCMC output.
- loo - https://mc-stan.org/users/interfaces/loo.html - efficient leave-one-out cross-validation and WAIC calculations.
- bayesplot - https://mc-stan.org/users/interfaces/bayesplot.html - ggplot2-based plotting library for graphing parameter estimates, MCMC diagnostics, and posterior predictive checks.
- rstantools - https://mc-stan.org/users/interfaces/rstantools.html - for developers of R packages interfacing with Stan
Experience
also installing the dependencies 'ucminf', 'numDeriv', 'bitops', 'ordinal', 'e1071', 'miniUI', 'zoo', 'RCurl', 'packrat', 'igraph', 'pan', 'jomo', 'classInt', 'units', 'gdata', 'colourpicker', 'DT', 'dygraphs', 'gtools', 'rsconnect', 'shinyjs', 'shinythemes', 'threejs', 'xts', 'ggridges', 'minqa', 'nloptr', 'flexmix', 'Formula', 'lmtest', 'modeltools', 'sandwich', 'brew', 'commonmark', 'praise', 'mvtnorm', 'Brobdingnag', 'globals', 'listenv', 'mitml', 'sp', 'spData', 'sf', 'deldir', 'LearnBayes', 'expm', 'gmodels', 'corpcor', 'tensorA', 'cubature', 'R.cache', 'StanHeaders', 'inline', 'gridExtra', 'RcppEigen', 'RUnit', 'shinystan', 'bayesplot', 'rstantools', 'lme4', 'betareg', 'HSAUR3', 'roxygen2', 'testthat', 'bridgesampling', 'matrixStats', 'nleqslv', 'coda', 'abind', 'future', 'RWiener', 'mice', 'spdep', 'mnormt', 'MCMCglmm', 'ape', 'arm', 'statmod', 'R.rsp', 'checkmate'
- Succeeded in 2462 seconds (41 minutes) Added something like 1,700 items.
- Uploading required 41 seconds. "Save R-rstan: Succeeded. 41.267s"
- Publish. Until it is published, a notebook's environments are only available to runtimes within itself.
- Exited Nextjournal.com completely.
- Then re-entered my notebook "Multi-level Regression for Sockeye Salmon Spawner Abundance." https://nextjournal.com/a/LLeNsGGztcMDLYmSt7BmT?token=TAAikv2TDXNQ7Dg3WieJgr
- via gear icon in "RUNTIMES" (upper left), from there the triangle in Environment.
- Searched for "Scott" to find this notebook "Create Environment ..."
- Selecting that notebook shows you the environment(s) in that notebook, in this case R_rstan.
- Selected that environment.
- Tried a one-statement R cell "library(rstan)". The environment for that cell is now marked R_rstan ... scheduling Runner: 71 seconds. Run Cell R_rstan ... Downloading R_rstan: 18 seconds ...
- ... <brief exposure to existential void> ...
- Run Cell R_rstan: Succeeded. rstan (Version 2.18.2, GitRev: 2e1f913d3ca3)
- Woo hoo!
# first, I created a runtime 'R_rstan' with 4 cores and 15 Gbytes. See gear icon "RUNTIMES" upper left. # then install.packages() as below. # finally save the environment and apply in other notebooks. install.packages( c('rstan','rstanarm', 'brms','loo'), dependencies=T, quiet=T); packageDate('rstan'); packageDate('rstanarm'); packageDate('brms'); packageDate('loo');