pystan.readthedocs.io Open in urlscan Pro
104.17.32.82  Public Scan

Submitted URL: http://pystan.readthedocs.io/
Effective URL: https://pystan.readthedocs.io/en/latest/
Submission: On June 05 via api from US — Scanned from DE

Form analysis 2 forms found in the DOM

GET search.html

<form class="search" action="search.html" method="get">
  <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false">
  <input type="submit" value="Go">
</form>

GET //readthedocs.org/projects/pystan/search/

<form id="flyout-search-form" class="wy-form" target="_blank" action="//readthedocs.org/projects/pystan/search/" method="get">
  <input type="text" name="q" aria-label="Search docs" placeholder="Search docs">
</form>

Text Content

PYSTAN¶

Release v3.9.1

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

 * Open source software: ISC License

(Upgrading from PyStan 2? We have you covered: Upgrading to Newer Releases.)


QUICK START¶

Install PyStan with python3 -m pip install pystan. PyStan runs on Linux and
macOS. You will also need a C++ compiler such as gcc ≥9.0 or clang ≥10.0.

This block of code shows how to use PyStan with a hierarchical model used to
study coaching effects across eight schools (see Section 5.5 of Gelman et al.
(2003)).

import stan

schools_code = """
data {
  int<lower=0> J;         // number of schools
  array[J] real y;              // estimated treatment effects
  array[J] real<lower=0> sigma; // 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, requires pandas



DOCUMENTATION¶

 * Getting Started
 * Installation
 * Upgrading to Newer Releases
 * API Reference
 * Plugins
 * Contributing to PyStan
 * Frequently Asked Questions


PYSTAN


NAVIGATION

 * Getting Started
 * Installation
 * Upgrading to Newer Releases
 * API Reference
 * Plugins
 * Contributing to PyStan
 * Frequently Asked Questions


RELATED TOPICS

 * Documentation overview
   * Next: Getting Started


QUICK SEARCH


1-Click Clusters On-demand. 2-week rentals. 16-512 NVIDIA H100, 3.2Tb/s
InfiniBand. Get started
Ad by EthicalAds   ·   ℹ️

©2019, pystan Developers. | Powered by Sphinx 7.2.6 & Alabaster 0.7.16 | Page
source
  v: latest
Versions latest stable On Read the Docs Project Home Builds Downloads On GitHub
View Edit Search


--------------------------------------------------------------------------------

Hosted by Read the Docs · Privacy Policy