Skip to content

Stan on the web! (thanks to RStudio)

This is big news. Thanks to RStudio, you can now run Stan effortlessly on the web.

So you can get started on Stan without any investment in set-up time, no need to install C++ on your computer, etc.

As Ben Goodrich writes, “RStudio Cloud is particularly useful for Stan tutorials where a lot of time can otherwise be wasted getting C++ toolchains installed and configured on everyone’s laptops.”

To get started with a simple example, just click here and log in.

We’ve pre-loaded this particular RStudio session with a regression model and an R script to simulate fake data and run the model. In your online RStudio Cloud session (which will appear within your browser when you click the above link), just go the lower-right window with Files, and click on simple_regression.stan and simple_regression.R. This will open up those files. Run simple_regression.R and it will simulate the data, run the Stan program, and produce a graph.

Now you can play around.

Create your own Stan program: just work in the upper-left window, click on File, New File, Stan File, then click on File, Save As, and give it a .stan extension. The RStudio editor already has highlighting and autocomplete for Stan files.

Or edit the existing Stan program (simple_regression.stan, sitting there in the lower right of your RStudio Cloud window), change it how you’d like, then edit the R script or create a new one. You can upload data to your session too.

When you run a new or newly edited Stan program, it will take some time to compile. But then next time you run it, R will access the compiled version and it will run faster.

You can also save your session and get back to it later.

Some jargon for ya—but I mean every word of it!

This is a real game-changer as it significantly lowers the barriers to entry for people to start using Stan.


Ultimately I recommend you set up Stan on your own computer so you have full control over your modeling, but RStudio’s Cloud is a wonderful way to get started.

Here’s what Rstudio says:

Each project is allocated 1GB of RAM. Each account is allocated one private space, with up to 3 members and 5 projects. You can submit a request to the RStudio Cloud team for more capacity if you hit one of these space limits, and we will do our best accomodate you. If you are using a Professional 2 account, you will not encounter these space limits.

In addition to the private space (where you can collaborate with a selected group of other users), every user also gets a personal workspace (titled “Your Workspace”), where there is virtually no limit to the number of projects you can create. Only you can work on projects in your personal workspace, but you can grant view & copy access to them to any other RStudio Cloud user.

This is just amazing. I’m not the most computer-savvy user, but I was able to get this working right away.

Ben adds:

It also comes with
* The other 500-ish examples in the examples/ subdirectory
* Most of the R packages that use Stan, including McElreath’s rethinking package from GitHub and all the ones under stan-dev, namely
– rstanarm (comes with compiled Stan programs for regression)
– brms (generates Stan programs for regression)
– projpred (for selecting a submodel of a GLM)
– bayesplot and shinystan (for visualizing posterior output)
– loo (for model comparison using expected log predictive density)
– rstantools (for creating your own R packages like rstanarm)
* Saving new / modified compiled Stan programs to the disk to use across sessions first requires the user to do rstan_options(auto_write = TRUE)

I’m so excited. You can now play with Stan yourself with no start-up effort. Or, if you’re already a Stan user, you can demonstrate it to your friends. Also, you can put your own favorite models in an RStudio Cloud environment (as Ben did for my simple regression model) and then share the link with other people, who can use your model on your data, upload their own data, alter your model, etc.

P.S. It seems that for now this is really only for playing around with very simple models, to give you a taste of Stan, and then you’ll have to install it on your computer to do more. See this post from Aki. That’s fine. as this demo is intended to be a show horse, not a work horse. I think there is also a way to pay RStudio for cycles on the cloud and then you can run bigger Stan models through the web interface. So that could be an option too, for example if you want to use Stan as a back-end for some computing that you’d like others to access remotely.


  1. Keith O’Rourke says:

    > Now you can play around.
    Hard to overestimate the impact of play.

  2. cugrad says:

    I always wanted to ask this: What kind of syntax is Stan? Is it like BUGS?

    Also, why would you do something like: real or int? It reminds me of static programming in C. Why would you want the user to specify it’s real or int? I never understood that.

    The user should focus on data analysis, not what type of number is supplied into Stan.

    • Andrew says:


      Bob can answer this better than I can, but very briefly:

      – Some lines of Stan look similar to some lines of Bugs, but fundamentally the two languages are very different. Bugs is declarative, Stan is imperative. The lines of a Stan program are executed in order. You can see more about it in the (free online) Stan manual.

      – Real or int arise because, for example, you can’t fit a Poisson model to a data point y=3.4. And you can’t have an array of length 7.2. There’s always a tradeoff with declarations in a program. You can do no declarations and try to let the program figure it out, but then this can make it harder to write programs once the models start to get more complicated.

      • Right, there’s a definite difference between strongly typed, and statically typed. There are plenty of dynamically typed languages that have strong type, for example if you say


        it will complain that you can’t index the array y with a real number (a type error), but clearly x went from having an integer 1 to a real/float 3.2 and so the name x is not statically typed to have a single kind of value.

        Stan has static typing, that is, you can know what the type of every variable is just by reading the code. With something like R if you read a value out of a file and assign it to a variable, that variables type will become whatever the type of the data read from the file was. That could be an int, a float, or a list, or a vector, or whatever. You have to interrogate the type by using a function that returns a description of the type. In R that’s “typeof”

        With Stan, if you declare

        int x;

        and then somehow try to calculate a number and assign it to x, if the number calculated isn’t an integer, it will bork rather than change the type. That’s because the type is statically declared, x will always be guaranteed to be an integer.

        I would say that Stan is heavily influenced by C and C++ syntax, and uses static typing and sequential imperative control structures (one line after another is computed in order).

    • Kharybdis says:

      If I recall correctly from the StanCon live stream, in future you can leave out the static type declarations and let Stan figure out the types for you. But perhaps indeed we need to wait for the cavalry to arrive.

      I actually like declaring the types; I’m afraid of dynamically typed languages. Although R is nice, but I never do anything that complicated with it.

Leave a Reply

Where can you find the best CBD products? CBD gummies made with vegan ingredients and CBD oils that are lab tested and 100% organic? Click here.