slimp


Nameslimp JSON
Version 0.4.0 PyPI version JSON
download
home_pagehttps://github.com/lamyj/slimp
SummaryLinear models with Stan and Pandas
upload_time2024-03-30 13:15:28
maintainerNone
docs_urlNone
authorJulien Lamy
requires_pythonNone
licenseMIT
keywords statistics bayesian linear-models stan pandas matplotlib
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # slimp: linear models with Stan and Pandas

*slimp* estimates linear models using [Stan](https://mc-stan.org/) and [Pandas](https://pandas.pydata.org/). Think [rstanarm](https://mc-stan.org/rstanarm/) or [brms](https://mc-stan.org/users/interfaces/brms), but in Python and faster.

Create the model:

```python
import matplotlib.pyplot
import numpy
import pandas
import slimp

y, x = numpy.mgrid[0:10, 0:10]
z = 10 + x + 2*y + numpy.random.normal(0, 2, (10, 10))
data = pandas.DataFrame({"x": x.ravel(), "y": y.ravel(), "z": z.ravel()})

model = slimp.Model("z ~ 1 + x + y", data, num_chains=4)
# Also possible to specify random seed
# model = slimp.Model("z ~ 1 + x + y", data, seed=42)
```

Sample the parameters, check the results:

```python
model.sample()
print(model.hmc_diagnostics)
print(model.summary()[["N_Eff", "R_hat"]].describe().loc[["min", "max"], :])
r_squared = slimp.r_squared(model)
print(r_squared.quantile([0.05, 0.95]))
```

Plot prior and posterior predictive checks:

```python
figure, plots = matplotlib.pyplot.subplots(1, 2, layout="tight", figsize=(8, 4))
slimp.predictive_plot(model, use_prior=True, plot_kwargs={"ax":plots[0]})
slimp.predictive_plot(model, use_prior=False, plot_kwargs={"ax":plots[1]})
```

Plot the credible intervals of the parameters and their distributions:

```
slimp.parameters_plot(model, include=["x", "y"])
slimp.KDEPlot(model.draws["sigma"], prob=0.90)
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/lamyj/slimp",
    "name": "slimp",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "statistics, bayesian, linear-models, stan, pandas, matplotlib",
    "author": "Julien Lamy",
    "author_email": "lamy@unistra.fr",
    "download_url": "https://files.pythonhosted.org/packages/6f/60/9244772c4f3fa07c557647ed2d100d1d35366ffd7bafb455965c570c3d30/slimp-0.4.0.tar.gz",
    "platform": null,
    "description": "# slimp: linear models with Stan and Pandas\n\n*slimp* estimates linear models using [Stan](https://mc-stan.org/) and [Pandas](https://pandas.pydata.org/). Think [rstanarm](https://mc-stan.org/rstanarm/) or [brms](https://mc-stan.org/users/interfaces/brms), but in Python and faster.\n\nCreate the model:\n\n```python\nimport matplotlib.pyplot\nimport numpy\nimport pandas\nimport slimp\n\ny, x = numpy.mgrid[0:10, 0:10]\nz = 10 + x + 2*y + numpy.random.normal(0, 2, (10, 10))\ndata = pandas.DataFrame({\"x\": x.ravel(), \"y\": y.ravel(), \"z\": z.ravel()})\n\nmodel = slimp.Model(\"z ~ 1 + x + y\", data, num_chains=4)\n# Also possible to specify random seed\n# model = slimp.Model(\"z ~ 1 + x + y\", data, seed=42)\n```\n\nSample the parameters, check the results:\n\n```python\nmodel.sample()\nprint(model.hmc_diagnostics)\nprint(model.summary()[[\"N_Eff\", \"R_hat\"]].describe().loc[[\"min\", \"max\"], :])\nr_squared = slimp.r_squared(model)\nprint(r_squared.quantile([0.05, 0.95]))\n```\n\nPlot prior and posterior predictive checks:\n\n```python\nfigure, plots = matplotlib.pyplot.subplots(1, 2, layout=\"tight\", figsize=(8, 4))\nslimp.predictive_plot(model, use_prior=True, plot_kwargs={\"ax\":plots[0]})\nslimp.predictive_plot(model, use_prior=False, plot_kwargs={\"ax\":plots[1]})\n```\n\nPlot the credible intervals of the parameters and their distributions:\n\n```\nslimp.parameters_plot(model, include=[\"x\", \"y\"])\nslimp.KDEPlot(model.draws[\"sigma\"], prob=0.90)\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Linear models with Stan and Pandas",
    "version": "0.4.0",
    "project_urls": {
        "Homepage": "https://github.com/lamyj/slimp"
    },
    "split_keywords": [
        "statistics",
        " bayesian",
        " linear-models",
        " stan",
        " pandas",
        " matplotlib"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6f609244772c4f3fa07c557647ed2d100d1d35366ffd7bafb455965c570c3d30",
                "md5": "12249d2f7c5721157d5e7010dc944ccd",
                "sha256": "f41b668a768342975773bbdd99b18f8a9a42c3687a9d07cd9e831170edc82da4"
            },
            "downloads": -1,
            "filename": "slimp-0.4.0.tar.gz",
            "has_sig": false,
            "md5_digest": "12249d2f7c5721157d5e7010dc944ccd",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 18345,
            "upload_time": "2024-03-30T13:15:28",
            "upload_time_iso_8601": "2024-03-30T13:15:28.741946Z",
            "url": "https://files.pythonhosted.org/packages/6f/60/9244772c4f3fa07c557647ed2d100d1d35366ffd7bafb455965c570c3d30/slimp-0.4.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-30 13:15:28",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "lamyj",
    "github_project": "slimp",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "slimp"
}
        
Elapsed time: 0.28053s