storopoli / Bayesian-Julia

Bayesian Statistics using Julia and Turing
https://storopoli.github.io/Bayesian-Julia
Creative Commons Attribution Share Alike 4.0 International
165 stars 28 forks source link
bayesian-statistics julia turing tutorials

Bayesian Statistics using Julia and Turing

CC BY-SA
4.0

Bayesian for Everyone!

Bayesian for Everyone!

Welcome to the repository of tutorials on how to do Bayesian Statistics using Julia and Turing. Tutorials are available at storopoli.io/Bayesian-Julia.

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.

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 to 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 covers most of the introduction to Julia and how to work with tabular data in Julia:

Turing

Turing is an 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

Jose Storopoli, PhD - Lattes CV - ORCID - https://storopoli.io

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.

To configure a local environment:

  1. Download and install Julia
  2. Clone the repository from GitHub: git clone https://github.com/storopoli/Bayesian-Julia.git
  3. Access the directory: cd Bayesian-Julia
  4. Activate the environment by typing in the Julia REPL:
    using Pkg
    Pkg.activate(".")
    Pkg.instantiate()

Tutorials

  1. Why Julia?
  2. What is Bayesian Statistics?
  3. Common Probability Distributions
  4. How to use Turing
  5. Markov Chain Monte Carlo (MCMC)
  6. Bayesian Linear Regression
  7. Bayesian Logistic Regression
  8. Bayesian Ordinal Regression
  9. Bayesian Regression with Count Data
  10. Robust Bayesian Regression
  11. Multilevel Models (a.k.a. Hierarchical Models)
  12. Computational Tricks with Turing (Non-Centered Parametrization and QR Decomposition)
  13. Epidemiological Models using ODE Solvers in Turing

Datasets

What about other Turing tutorials?

Despite not being the only Turing tutorial that exists, this tutorial 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

I also have a free and opensource graduate course on Bayesian Statistics with Turing and Stan code. You can find it at storopoli/Bayesian-Statistics.

How to cite

To cite these tutorials, please use:

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

Or in BibTeX format (LaTeX):

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

References

The references are divided in books, papers, software, and datasets.

Books

Academic Papers

Software

Datasets

License

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

CC BY-SA 4.0