pystan


Namepystan JSON
Version 3.9.1 PyPI version JSON
download
home_pagehttps://mc-stan.org
SummaryPython interface to Stan, a package for Bayesian inference
upload_time2024-04-12 14:20:45
maintainerNone
docs_urlNone
authorAllen Riddell
requires_python<4.0,>=3.9
licenseISC
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ******
PyStan
******

**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
===============

Install PyStan with ``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.

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.

.. code-block:: python

    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`


Citation
========

We appreciate citations as they let us discover what people have been doing
with the software. Citations also provide evidence of use which can help in
obtaining grant funding.

To cite PyStan in publications use:

Riddell, A., Hartikainen, A., & Carter, M. (2021). PyStan (3.0.0). https://pypi.org/project/pystan

Or use the following BibTeX entry::

    @misc{pystan,
      title = {pystan (3.0.0)},
      author = {Riddell, Allen and Hartikainen, Ari and Carter, Matthew},
      year = {2021},
      month = mar,
      howpublished = {PyPI}
    }

Please also cite Stan.

            

Raw data

            {
    "_id": null,
    "home_page": "https://mc-stan.org",
    "name": "pystan",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.9",
    "maintainer_email": null,
    "keywords": null,
    "author": "Allen Riddell",
    "author_email": "riddella@indiana.edu",
    "download_url": "https://files.pythonhosted.org/packages/a4/dd/716f18cde8ee9471ad742a3de15a6ad586c979b3f92b9a6a3ad4b8aef830/pystan-3.9.1.tar.gz",
    "platform": null,
    "description": "******\nPyStan\n******\n\n**PyStan** is a Python interface to Stan, a package for Bayesian inference.\n\nStan\u00ae is a state-of-the-art platform for statistical modeling and\nhigh-performance statistical computation. Thousands of users rely on Stan for\nstatistical modeling, data analysis, and prediction in the social, biological,\nand physical sciences, engineering, and business.\n\nNotable features of PyStan include:\n\n* Automatic caching of compiled Stan models\n* Automatic caching of samples from Stan models\n* An interface similar to that of RStan\n* Open source software: ISC License\n\nGetting started\n===============\n\nInstall PyStan with ``pip install pystan``. PyStan runs on Linux and macOS. You will also need a C++ compiler such as gcc \u22659.0 or clang \u226510.0.\n\nThe 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.\n\n.. code-block:: python\n\n    import stan\n\n    schools_code = \"\"\"\n    data {\n      int<lower=0> J;         // number of schools\n      array[J] real y;              // estimated treatment effects\n      array[J] real<lower=0> sigma; // standard error of effect estimates\n    }\n    parameters {\n      real mu;                // population treatment effect\n      real<lower=0> tau;      // standard deviation in treatment effects\n      vector[J] eta;          // unscaled deviation from mu by school\n    }\n    transformed parameters {\n      vector[J] theta = mu + tau * eta;        // school treatment effects\n    }\n    model {\n      target += normal_lpdf(eta | 0, 1);       // prior log-density\n      target += normal_lpdf(y | theta, sigma); // log-likelihood\n    }\n    \"\"\"\n\n    schools_data = {\"J\": 8,\n                    \"y\": [28,  8, -3,  7, -1,  1, 18, 12],\n                    \"sigma\": [15, 10, 16, 11,  9, 11, 10, 18]}\n\n    posterior = stan.build(schools_code, data=schools_data)\n    fit = posterior.sample(num_chains=4, num_samples=1000)\n    eta = fit[\"eta\"]  # array with shape (8, 4000)\n    df = fit.to_frame()  # pandas `DataFrame`\n\n\nCitation\n========\n\nWe appreciate citations as they let us discover what people have been doing\nwith the software. Citations also provide evidence of use which can help in\nobtaining grant funding.\n\nTo cite PyStan in publications use:\n\nRiddell, A., Hartikainen, A., & Carter, M. (2021). PyStan (3.0.0). https://pypi.org/project/pystan\n\nOr use the following BibTeX entry::\n\n    @misc{pystan,\n      title = {pystan (3.0.0)},\n      author = {Riddell, Allen and Hartikainen, Ari and Carter, Matthew},\n      year = {2021},\n      month = mar,\n      howpublished = {PyPI}\n    }\n\nPlease also cite Stan.\n",
    "bugtrack_url": null,
    "license": "ISC",
    "summary": "Python interface to Stan, a package for Bayesian inference",
    "version": "3.9.1",
    "project_urls": {
        "Documentation": "https://pystan.readthedocs.io",
        "Homepage": "https://mc-stan.org",
        "Repository": "https://github.com/stan-dev/pystan"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "20e7726e923d328524d0151080f5a1d20f57a025b6d2f72a252c2d2d7abe57f9",
                "md5": "094d840d37c4836708c1d454c97c4fde",
                "sha256": "c40235ffdabdc762eed2ba3f675a2096e9baf0734c7d310c88384f433fd49952"
            },
            "downloads": -1,
            "filename": "pystan-3.9.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "094d840d37c4836708c1d454c97c4fde",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.9",
            "size": 13903,
            "upload_time": "2024-04-12T14:20:43",
            "upload_time_iso_8601": "2024-04-12T14:20:43.253887Z",
            "url": "https://files.pythonhosted.org/packages/20/e7/726e923d328524d0151080f5a1d20f57a025b6d2f72a252c2d2d7abe57f9/pystan-3.9.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a4dd716f18cde8ee9471ad742a3de15a6ad586c979b3f92b9a6a3ad4b8aef830",
                "md5": "7df52b7e8024cae9d6baf6a8f8ce620e",
                "sha256": "e4decab664006f638ffb5ca6333c848b015ee1ae11ccd9636f8a05b844bc7aef"
            },
            "downloads": -1,
            "filename": "pystan-3.9.1.tar.gz",
            "has_sig": false,
            "md5_digest": "7df52b7e8024cae9d6baf6a8f8ce620e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.9",
            "size": 13795,
            "upload_time": "2024-04-12T14:20:45",
            "upload_time_iso_8601": "2024-04-12T14:20:45.723979Z",
            "url": "https://files.pythonhosted.org/packages/a4/dd/716f18cde8ee9471ad742a3de15a6ad586c979b3f92b9a6a3ad4b8aef830/pystan-3.9.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-12 14:20:45",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "stan-dev",
    "github_project": "pystan",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pystan"
}
        
Elapsed time: 0.24122s