slimp


Nameslimp JSON
Version 1.0.0 PyPI version JSON
download
home_pagehttps://github.com/lamyj/slimp
SummaryLinear models with Stan and Pandas
upload_time2025-02-10 21:08:01
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)
```

Use a custom Stan model: have a look [here](custom_model_example/README.md)

            

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/7d/6d/b21d2266604a84f3dcbac488829c7e3b6c419dedc661e3470f0cecae3375/slimp-1.0.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\nUse a custom Stan model: have a look [here](custom_model_example/README.md)\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Linear models with Stan and Pandas",
    "version": "1.0.0",
    "project_urls": {
        "Homepage": "https://github.com/lamyj/slimp"
    },
    "split_keywords": [
        "statistics",
        " bayesian",
        " linear-models",
        " stan",
        " pandas",
        " matplotlib"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b2d059938ffe84593d5650e2292ed9e2489cdfe26d3cdd0ac687a6f663e68d99",
                "md5": "a975fa9bc450ff17b56b697f607fe1f6",
                "sha256": "625c3f718a7f854536cb6c99b242277bc8b3f793a831297742f91a23aa3054c1"
            },
            "downloads": -1,
            "filename": "slimp-1.0.0-py3-none-manylinux_2_34_x86_64.whl",
            "has_sig": false,
            "md5_digest": "a975fa9bc450ff17b56b697f607fe1f6",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 1774025,
            "upload_time": "2025-02-10T21:07:58",
            "upload_time_iso_8601": "2025-02-10T21:07:58.721177Z",
            "url": "https://files.pythonhosted.org/packages/b2/d0/59938ffe84593d5650e2292ed9e2489cdfe26d3cdd0ac687a6f663e68d99/slimp-1.0.0-py3-none-manylinux_2_34_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7d6db21d2266604a84f3dcbac488829c7e3b6c419dedc661e3470f0cecae3375",
                "md5": "4761b7fb8ce4acd918e6c5c4d5b12988",
                "sha256": "697f619e128dd9a25dd85e156ea361160a8880452094a3ce8e1eac039d8725f9"
            },
            "downloads": -1,
            "filename": "slimp-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "4761b7fb8ce4acd918e6c5c4d5b12988",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 25807,
            "upload_time": "2025-02-10T21:08:01",
            "upload_time_iso_8601": "2025-02-10T21:08:01.587973Z",
            "url": "https://files.pythonhosted.org/packages/7d/6d/b21d2266604a84f3dcbac488829c7e3b6c419dedc661e3470f0cecae3375/slimp-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-02-10 21:08:01",
    "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.40134s