stan-dev / cmdstanpy

CmdStanPy is a lightweight interface to Stan for Python users which provides the necessary objects and functions to compile a Stan program and fit the model to data using CmdStan.
BSD 3-Clause "New" or "Revised" License
149 stars 68 forks source link

notebook - CmdStanPy to Arviz #482

Open mitzimorris opened 2 years ago

mitzimorris commented 2 years ago

Summary:

We need a case study with examples on how the CmdStanPy - Arviz interface works.

Description:

This should be another example in this list:

From README.md

CmdStanPy produces a MCMC sample (or point estimate) from the posterior; other packages do analysis and visualization.

We need to show how easy this is - highlight use of stan_variables, etc.

Current Version:

mitzimorris commented 2 years ago

I have a notebook here: https://github.com/maxbiostat/StanConnect2021_Biostatistics/blob/main/talk_1/Coding%20the%20BYM2%20model%20for%20disconnected%20graphs%20in%20Stan.ipynb

but any of the Stan case studies would be fair game.

WardBrian commented 2 years ago

I also have the first 5 chapters of McElreath’s Rethinking translated to CmdStanPy+Arviz as options, I can upload them somewhere

bob-carpenter commented 2 years ago

Should be "produces an MCMC sample" (for those following along at home, the choice of "an" vs. "a" in English s pronunciation based).

Does CmdStanPy also return samples from VI and from Laplace approximations derived from optimization? The only point estimates we expose are from optimization, but they exist under the hood for VI, too.

Plus, CmdStanPy can produce penalized maximum likelihood estimates, which aren't technically point estimates from Bayesian posteriors (we turn off the Jacobian, so they're not actually MAP estimates from the unconstrained Bayesian estimates, either).

You can see how I described the inference capabilities on the mc-stan.org home page.

WardBrian commented 2 years ago

One of the Arviz devs (@OriolAbril) put together this notebook which does more or less exactly this: https://oriolabrilpla.cat/python/arviz/stan/xarray/xarray-einstats/2022/04/25/einstats-hmm-cmdstanpy.html

I suppose a question is if we need another version of this kind of thing which lives specifically inside the cmdstanpy documentation?