Code Monkey home page Code Monkey logo

learn-stan's Introduction

TL:DR

The slide for this workshop are available here

The code for the slides lives in slides.Rmd

There are also a few example scripts, for example hake_schaefer_model.R shows how to fit a Schaefer model given catch and CPUE data from a hake fishery.

A Practical Introduction to Stan

The goal of this repo is to get users comfortable writing, diagnosing, and using Stan models. I assume that if you’re reading this you know you want to do Bayesian modeling and you’re interested in learning how to do it in Stan. If you’re not quite there yet, some of the terminology in here may be confusing, and I strongly recommend

Recommended Books

Online Resources

This workshop also assumes you work in or are at least comfortable with R.

There are lots of more detailed and technical resources for learning Stan out there, and any user interested in using Stan in their research should be sure to read further to really understand what Stan is doing and why (the official documentation is very good, and Monnahan et al. 2016 provides a great introduction to Stan for those with an Ecological bent).

However, many of the available resources can be daunting to people unfamiliar with the Stan, or omit key steps in the “ok, but how do I actually do this” side of things. This workshop is intended to help users go from raw data to model fitting with real data and real use cases. This document is not intended to be a technically perfect explanation or example of the use of Stan, but rather a step-by-step example of how I at least have dealt with many of the kinds of problems that practical users encounter in using Stan (i.e. explanations are intended to be clear, not necessarily precise). Hopefully you can use this as a foundation then for building more rigorous analyses of your in in R and Stan. (Constructive) Comments and suggestions appreciated!

Setup

Installing Stan

Instructions for installing rstan are provided in the following wiki

https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started

It doesn’t matter if you want to install the development or official release.

Stan is a compiled language, meaning that there is some behind-the-scenes setup to your C++ toolchain that needs to be done so your computer can handle it.

Follow these instructions prior to trying to install rstan. The wiki contains links to instructions for setting up your C++ toolchain up here.

The instructions will vary depending on what operating system you use, and even the version of that operating system, and the version of R you are using. If you’re usually generally up-to-date systems this should be pretty straightforward, but the older the system you are running the trickier things might get, particularly if you are using R versions < 4.X

If you’ve never run any compiled languages before, the initial setup can take some time (e.g. downloading all the toolchain components on a Mac), so I recommend not trying to do this the morning of the workshop if your goal is to follow along.

Once you’ve configured your toolchain and installed rstan, you can test to make sure everything is working by opening R and running

library(rstan)
example(stan_model, package = "rstan", run.dontrun = TRUE)

Share and enjoy!

Installing dependencies

This repository is equipped with renv.

To install the required packages, simply install the renv package using

install.packages("renv")

And then after ensuring the working directory is appropriately set to the location of the project for this repository, running

renv::restore()

And following all prompts. To the best of its abilities renv will install the appropriate versions of the packges needed to run this repo, and will not affect other versions of your packages located in your main library.

learn-stan's People

Contributors

danovando avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.