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.
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'])
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'])
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.