Installing RStan in Ubuntu

September 3, 2012
By

(This article was first published on The Ubuntu R Blog, and kindly contributed to R-bloggers)

Based on RStan Getting Started

R packages

Assuming you have the most up to date version of R, the following packages need to be installed. This assumes you have the c2d4u PPA available. See here for more information.

  sudo apt-get install r-cran-rcpp r-cran-inline r-cran-rcpp

C++ Compiler

You probably have a C++ compiler installed, but just in case:

   sudo apt-get install build-essential

The “RStan Getting Started” page suggests modifying the C++ compiler optimization level. On my install of Ubuntu, the optimization was set as the page suggested. You can check with:

   grep "CXXFLAGS =" /usr/lib/R/etc/Makeconf

Among the output of grep, you should see:

   CXXFLAGS = -O3 -pipe  -g $(LTO)

If you do not, use your favorite editor to edit “/ust/lib/R/etc/Makeconf” so that the CXXFLAGS line has “-03” as well as everything else that is there.

Install RStan

From within R, run the following commands. You will need to select a mirror, although it shouldn’t actually use it.

   options(repos = c(getOption("repos"), 
    rstan = "http://wiki.stan.googlecode.com/git/R"))
   install.packages('rstan', type = 'source')

It is a large download (for R, 2.3 Mb) and will take some time to compile.

Testing RStan

Now that RStan is installed, you can test it with the following code. RStan compiles the model, then runs it. It will take much longer to compile the code than it takes to generate the samples.

To leave a comment for the author, please follow the link and comment on their blog: The Ubuntu R Blog.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Sponsors

Mango solutions



RStudio homepage



Zero Inflated Models and Generalized Linear Mixed Models with R

Quantide: statistical consulting and training



http://www.eoda.de







ODSC

ODSC

CRC R books series











Contact us if you wish to help support R-bloggers, and place your banner here.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)