Skip to content
This repository has been archived by the owner on Feb 21, 2023. It is now read-only.

storopoli/Turing-Workshop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Workshop of Bayesian Statistics with Julia and Turing

CC BY-SA 4.0

Bayesian for Everyone!

Bayesian for Everyone!

This is a Turing Workshop on how to do Bayesian Statistics. The Workshop is heavily based on tutorials available at storopoli.io/Bayesian-Julia. If you want you can see the YouTube video from the recorded workshop at Stuttgart Julia Programming Language Meetup Group.

Bayesian statistics is an approach to inferential statistics based on Bayes' theorem, where available knowledge about parameters in a statistical model is updated with the information in observed data. The background knowledge is expressed as a prior distribution and combined with observational data in the form of a likelihood function to determine the posterior distribution. The posterior can also be used for making predictions about future events.

Bayesian statistics is a departure from classical inferential statistics that prohibits probability statements about parameters and is based on asymptotically sampling infinite samples from a theoretical population and finding parameter values that maximize the likelihood function. Mostly notorious is null-hypothesis significance testing (NHST) based on p-values. Bayesian statistics incorporate uncertainty (and prior knowledge) by allowing probability statements about parameters, and the process of parameter value inference is a direct result of the Bayes' theorem.

$$\underbrace{P(\theta \mid y)}{\text{Posterior}} = \frac{\overbrace{P(y \mid \theta)}^{\text{Likelihood}} \cdot \overbrace{P(\theta)}^{\text{Prior}}}{\underbrace{P(y)}{\text{Normalizing Costant}}}$$

Table of Contents

Julia

Julia is a fast dynamic-typed language that just-in-time (JIT) compiles into native code using LLVM. It "runs like C but reads like Python", meaning that is blazing fast, easy to prototype and read/write code. It is multi-paradigm, combining features of imperative, functional, and object-oriented programming. I won't cover Julia basics and any sort of data manipulation using Julia in the tutorials, instead please take a look into the following resources which cover most of the introduction to Julia and how to work with tabular data in Julia:

  • Julia Documentation: Julia documentation is a very friendly and well-written resource that explains the basic design and functionality of the language.
  • Thinking Julia: introductory beginner-friendly book that explains the main concepts and functionality behind the Julia language.
  • Julia High Performance: book by two of the creators of the Julia Language (Avik Sengupta and Alan Edelman), it covers how to make Julia even faster with some principles and tricks of the trade.
  • An Introduction DataFrames: the package DataFrames.jl provides a set of tools for working with tabular data in Julia. Its design and functionality are similar to those of pandas (in Python) and data.frame, data.table and dplyr (in R), making it a great general purpose data science tool, especially for those coming to Julia from R or Python.This is a collection of notebooks that introduces DataFrames.jl made by one of its core contributors Bogumił Kamiński.

Turing

Turing is a ecosystem of Julia packages for Bayesian Inference using probabilistic programming. Models specified using Turing are easy to read and write — models work the way you write them. Like everything in Julia, Turing is fast.

Author

José Eduardo Storopoli, PhD - Lattes CV - ORCID - https://storopoli.io

josees@uni9.pro.br

I would like to thank Stuttgart Julia Programming Language Meetup Group and Juliane Weilbach for the opportunity to present the first version of this Workshop.

How to use the content?

The content is licensed under a very permissive Creative Commons license (CC BY-SA). You are mostly welcome to contribute with issues and pull requests. My hope is to have more people into Bayesian statistics. The content is aimed towards social scientists and PhD candidates in social sciences. I chose to provide an intuitive approach rather than focusing on rigorous mathematical formulations. I've made it to be how I would have liked to be introduced to Bayesian statistics.

Just access storopoli.io/Turing-Workshop and click on Edit or run this notebook and then click on binder!

To configure a local environment:

  1. Download and install Julia
  2. Clone the repository from GitHub: git clone https://github.com/storopoli/Turing-Workshop.git
  3. Access the directory: cd Turing-Workshop
  4. Run the Pluto Notebook by typing in the Julia REPL:
    using Pluto
    Pluto.run(notebook="Turing_Workshop.jl")

What about other Turing tutorials?

Despite not being the only Turing tutorial that exists, this workshop aims to introduce Bayesian inference along with how to use Julia and Turing. Here is a (not complete) list of other Turing tutorials:

  1. Official Turing Tutorials: tutorials on how to implement common models in Turing
  2. Statistical Rethinking - Turing Models: Julia versions of the Bayesian models described in Statistical Rethinking Edition 1 (McElreath, 2016) and Edition 2 (McElreath, 2020)
  3. Håkan Kjellerstrand Turing Tutorials: a collection of Julia Turing models

How to cite

To cite these tutorials, please use:

Storopoli (2021). Workshop of Bayesian Statistics with Julia and Turing. https://storopoli.io/Turing-Workshop.

Or in BibTeX format (LaTeX):

@misc{storopoli2021turingworkshop,
  author = {Storopoli, Jose},
  title = {Workshop of Bayesian Statistics with Julia Turing},
  url = {https://storopoli.io/Turing-Workshop},
  year = {2021}
}

Recommended Books

Bayesian Data Analysis
Bayesian Data Analysis
Bayesian Data Analysis
Bayesian Data Analysis

License

This content is licensed under Creative Commons Attribution-ShareAlike 4.0 Internacional.

CC BY-SA 4.0