Skip to content

Getting Started with CmdStan

Dustin Tran edited this page Aug 11, 2015 · 15 revisions

Set up CmdStan

  1. Clone CmdStan.

    git clone https://github.com/stan-dev/cmdstan.git
    
  2. Initialize and update Stan (within CmdStan).

    From the cmdstan home directory

    make stan-update
    

Build a Stan Model

The make target help will display options.

  1. Build all tools (optional) make build

  2. Build a model foo/bar.stan

    linux / mac: make foo/bar

    windows: make foo/bar.exe

An example

From the cmdstan home directory

make examples/bernoulli/bernoulli
examples/bernoulli/bernoulli sample data file=examples/bernoulli/bernoulli.data.R
bin/print output.csv

This compiles the bernoulli.stan model specified in the examples/bernoulli folder. We then run the default sampling algorithm with the bernoulli.data.R data, which by default outputs a file output.csv in the current directory. We then run the print script in bin/ which summarizes the information in the file.

Other tips

Using a different Stan branch

If the branch is feature/foo-bar, from the cmdstan home directory:

make stan-update/feature/foo-bar

Keeping CmdStan up-to-date

Simply run make stan-update from the cmdstan home directory.

On the file structure

It may be helpful at times to run manual git commands in the repos. Stan is a submodule within CmdStan and is located in the stan/ folder. The math library is a submodule within Stan and is located in the stan/lib/stan_math directory. To keep everything up-to-date manually, run git pull within the home directory of each repo (cmdstan, stan, and math). Similarly, to change branches for one of these repos, simply git checkout that branch within the home directory of that repo.

Clone this wiki locally