Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

PyStan

NOTE: This documentation describes a BETA release of PyStan 3.

PyStan is a Python interface to Stan, a package for Bayesian inference.

Stan® is a state-of-the-art platform for statistical modeling and high-performance statistical computation. Thousands of users rely on Stan for statistical modeling, data analysis, and prediction in the social, biological, and physical sciences, engineering, and business.

Notable features of PyStan include:

  • Automatic caching of compiled Stan models

  • Automatic caching of samples from Stan models

  • An interface similar to that of RStan

  • Open source software: ISC License

Getting started

NOTE: BETA versions of PyStan 3 must be installed with ``pip install –pre pystan``.

Install PyStan with pip install pystan. (PyStan requires Python 3.7 or higher running on a Linux or macOS system.)

The following block of code shows how to use PyStan with a model which studied coaching effects across eight schools (see Section 5.5 of Gelman et al (2003)). This hierarchical model is often called the “eight schools” model.

import stan

schools_code = """
data {
  int<lower=0> J;         // number of schools
  real y[J];              // estimated treatment effects
  real<lower=0> sigma[J]; // standard error of effect estimates
}
parameters {
  real mu;                // population treatment effect
  real<lower=0> tau;      // standard deviation in treatment effects
  vector[J] eta;          // unscaled deviation from mu by school
}
transformed parameters {
  vector[J] theta = mu + tau * eta;        // school treatment effects
}
model {
  target += normal_lpdf(eta | 0, 1);       // prior log-density
  target += normal_lpdf(y | theta, sigma); // log-likelihood
}
"""

schools_data = {"J": 8,
                "y": [28,  8, -3,  7, -1,  1, 18, 12],
                "sigma": [15, 10, 16, 11,  9, 11, 10, 18]}

posterior = stan.build(schools_code, data=schools_data)
fit = posterior.sample(num_chains=4, num_samples=1000)
eta = fit["eta"]  # array with shape (8, 4000)
df = fit.to_frame()  # pandas `DataFrame`

Metadata

Release files for pystan 3.0.0b4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pystan 3.0.0b4
File Size Uploaded
pystan-3.0.0b4.tar.gz 11.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pystan 3.0.0b4
File Interpreter ABI Platform
pystan-3.0.0b4-py3-none-any.whl Python 3 none any Details

Total release size: 22.0 kB

Release files / pystan-3.0.0b4.tar.gz

Download URL pystan-3.0.0b4.tar.gz
Size 11.3 kB
Tags Source
SHA-256 checksum
How to use checksums
89cef69b976cc1185db8806e625c0bff184e7d75f03f1ce8f672ca2d04cb8535
BLAKE2b-256 checksum
How to use checksums
500e029c06c493f14964125ee27eb013852e2185d879315c1e4cdf622bd56cf9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.10 CPython/3.9.0 Linux/5.4.0-1031-azure

Release files / pystan-3.0.0b4-py3-none-any.whl

Download URL pystan-3.0.0b4-py3-none-any.whl
Size 10.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5cf3f43751f4dad3390f1e01dbbf36b7eec77d6c3607cb711214bc4872faa6e2
BLAKE2b-256 checksum
How to use checksums
e8e7bced1967538087a2d3475fd5cad32e0f7c43d72cdfdba26cd0c37b914e63
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.10 CPython/3.9.0 Linux/5.4.0-1031-azure

Release history Release notifications | RSS feed

3.14.0

2 release files

3.10.1

2 release files

3.9.1

2 release files

3.9.0

2 release files

3.8.0

2 release files

3.7.0

2 release files

3.6.0

2 release files

3.5.0

2 release files

3.4.0

2 release files

3.3.0

2 release files

3.2.0

2 release files

3.1.1

2 release files

3.1.0

2 release files

3.0.2

2 release files

3.0.1

2 release files

3.0.0

2 release files

This release

3.0.0b4 This release

2 release files

2.7.0.0

1 release file

2.4.0.0

1 release file

2.3.0.0

1 release file

2.2.0.1

1 release file

2.2.0.0

1 release file

2.1.0.1

1 release file

2.1.0.0

1 release file

2.0.1.3

1 release file

2.0.1.1

1 release file

2.0.1.0

1 release file

2.0.0.1

1 release file

2.0.0.0

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page