Code Monkey home page Code Monkey logo

statisticalrethinkingstan.jl's Introduction

Purpose of SR2StanPluto.jl

As stated many times by the author in his online lectures, StatisticalRethinking is a hands-on course. This project is intended to assist with the hands-on aspect of learning the key ideas in StatisticalRethinking.

SR2StanPluto is a Julia project that uses Pluto notebooks for this purpose. Each notebook demonstrates Julia versions of code snippets and mcmc models contained in the R package "rethinking" associated with the book Statistical Rethinking by Richard McElreath.

This Julia project uses Stan (the cmdstan executable) as the underlying mcmc implementation.

Important note

From v5 onwards the basis will no longer be StatisticalRethinking.jl but RegressionAndOtherStories.jl. Both packages have very similar content, but StatisticalRethinking.jl uses Plots.jl while RegressionAndOtherStories.jl is using Makie.jl.

Tagged version 4.2.0 is the last more or less complete set of scripts covering the old chapters 1 to 11.

Usage

To (locally) reproduce and use this project, do the following:

  1. Download this project from Github and move to the downloaded directory, e.g.:
$ cd .julia/dev
$ git clone https://github.com/StatisticalRethinkingJulia/SR2StanPluto.jl SR2StanPluto
$ cd SR2StanPluto

The next step assumes your basic Julia environment includes Pkg and Pluto.

  1. Start a Pluto notebook server.
$ cd notebooks
$ julia

julia> using Pluto
julia> Pluto.run()
  1. A Pluto page should open in a browser.

  2. Select a notebook in the open a file entry box, e.g. type ./ and select a notebook.

Usage details

All "rethinking" data files are stored and maintained in StatisticalRethinking.jl and can be accessed via sr_datadir(...). See notebooks/00-Preface.jl for an example.

In scripts, for naming models and results of simulations I tend to use:

Models and results:

  1. stan5_1 : Stan language program
  2. m5_1s : The sampled StanSample model
  3. q5_1s : Stan quap model (NamedTuple similar to Turing)

Draws:

  1. chns5_1s : MCMCChains object (4000 samples from 4 chains)
  2. part5_1s : Stan samples (Particles notation)
  3. quap5_1s : Quap samples (Particles notation)
  4. nt5_1s : NamedTuple with samples values
  5. ka5_1s : KeyedArray object (see AxisArrays.jl)
  6. da5_1s : DimArray object (see DimensionalData.jl)
  7. st5_1s : StanTable 0bject (see Tables.jl)
  8. i5_1s : InferenceObjects (see InferenceObjects.jl)

The default for read_samples(m1_1s) is a StanTable chains object.

Results as a DataFrame:

  1. prior5_1s_df : Prior samples (DataFrame)
  2. post5_1s_df : Posterior samples (DataFrame)
  3. quap5_1s_df : Quap approximation to posterior samples (DataFrame)
  4. pred5_1s_df : Posterior predictions (DataFrame)

The s at the end indicates Stan.

By default read_samples(m5_1s) returns a StanTable with the results. In general it is safer to specify the desired format, i.e. read_samples(m5_1s, :table) as the Julia eco-sytem is still evolving rapidly with new options.

Using read_samples(m5_1s, :...) makes it easy to convert samples to other formats.

In version 5 I expect to mainly use the output_formats :dataframe, :namedtuple.

For InferenceObjects.jl there is a separate function inferencedata(m1_1s). See the Notebook_Examples in Stan.jl for an example Pluto notebook.

Status

SR2StanPluto.jl is compatible with the 2nd edition of the book.

StructuralCausalModels.jl ans ParetoSmoothedImportanceSampling.jl are included as experimental dependencies in the StatisticalRethinking.jl v3+ package. Both definitely WIP! See also below version 5 info.

Any feedback is appreciated. Please open an issue.

Acknowledgements

Of course, without the excellent textbook by Richard McElreath, this project would not have been possible. The author has also been supportive of this work and gave permission to use the datasets.

This repository and format is derived from previous versions of StatisticalRethinking.jl, work by Karajan, Max Lapan and many other contributors.

Versions

Version 5 (under development, 2023)

  1. Switch to (GL)Makie.jl, Graphs.jl, CausalInference.jl, InferenceObjects.jl (and more probably).

Version 4

  1. SR2StanPluto v4+ requires StatisticalRethinking v4+.

versions 2 & 3

  1. Many additions for 2nd edition of Statistical Rethinking book.
  2. Version 3 switched to using StanSample and StanQuap

Version 1

  1. Initial versions (late Nov 2020).

statisticalrethinkingstan.jl's People

Contributors

goedman avatar pitmonticone avatar

Watchers

James Cloos 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.