Skip to main content

A collection of tools for analysing cmdspanpy output, written in Python

Project description

A Python library for analysing cmdstanpy output

This is a collection of function for analysing output of cmdstanpy library. The main idea is to do a quick data analysis by calling a single function that makes:

  • traceplots of samples,

  • text and plots of the summaries of model parameters,

  • histograms and pair plots of posterior distributions of parameters.

Picture of Tarpan

The only known illustration of a tarpan made from life, depicting a five month old colt (Borisov, 1841). Source: Wikimedia Commons.

Setup

First, install cmdstanpy library, and then do:

pip install tarpan

Usage

Do complete analysis: save_analysis

This is the main function of the library that saves summaries and trace/pair/tree plots in model_info directory. See the example code of using save_analysis function and description of its output files.

from tarpan.cmdstanpy.analyse import save_analysis
model = CmdStanModel(stan_file="your_model.stan")
fit = model.sample(data=your_data)
save_analysis(fit, param_names=['mu', 'sigma'])

Make tree plot: save_tree_plot

Function save_tree_plot creates a tree plot in model_info directory. See example code here.

from tarpan.cmdstanpy.tree_plot import save_tree_plot
fit = CmdStanModel(stan_file="your_model.stan")
save_tree_plot([fit], param_names=['mu', 'sigma'])
Tree plot

Comparing multiple models on a tree plot

Supply multiple fits in order to compares parameters from multiple models. See example code here.

from tarpan.cmdstanpy.tree_plot import save_tree_plot
fit1 = CmdStanModel(stan_file="your_model1.stan")
fit2 = CmdStanModel(stan_file="your_model2.stan")

data = { "mu": 2.2, "tau": 1.3 }  # Add extra markers (optional)
save_tree_plot([fit1, fit2], extra_values=data, param_names=['mu', 'sigma'])
Tree plot with multiple models

Run unit tests

pytest

The unlicense

This work is in public domain.

🐴🐴🐴

This work is dedicated to Tarpan, an extinct subspecies of wild horse.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tarpan-0.1.9.tar.gz (13.8 kB view hashes)

Uploaded Source

Built Distribution

tarpan-0.1.9-py3-none-any.whl (19.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page