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.0b3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pystan-3.0.0b3.tar.gz | 11.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pystan-3.0.0b3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 21.9 kB
Release files / pystan-3.0.0b3.tar.gz
| Download URL | pystan-3.0.0b3.tar.gz |
|---|---|
| Size | 11.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
82bd7a6bed3f31d3d925b4240f52f8ab58b3cc2d06fa4ac641759d8a9add9637
|
|
BLAKE2b-256 checksum How to use checksums |
3b9bfb02df9f558c1f63325581d0888678c36cd99b8e5710c4c5d08f9ae249a4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.10 CPython/3.8.6 Linux/5.4.0-1026-azure
|
Release files / pystan-3.0.0b3-py3-none-any.whl
| Download URL | pystan-3.0.0b3-py3-none-any.whl |
|---|---|
| Size | 10.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0d4e28d22aeb522a5372a5eee1a3ff92876df05f6347f5fe035036792dfb7807
|
|
BLAKE2b-256 checksum How to use checksums |
c87ced86cac075c29740af756997008f7c1069b0068c6d34510cfa67accbcc9e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.10 CPython/3.8.6 Linux/5.4.0-1026-azure
|