bambi

BAyesian Model-Building Interface (Bambi) in Python.

https://github.com/bambinos/bambi

Science Score: 67.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 1 DOI reference(s) in README
  • Academic publication links
  • Committers with academic emails
    1 of 46 committers (2.2%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (21.3%) to scientific vocabulary

Keywords

bayesian-inference bayesian-statistics python regression-models statistical-analysis statistical-modeling

Keywords from Contributors

closember optimizing-compiler wx tk qt gtk probability-distribution transpiler scipy-stats einsum
Last synced: 6 months ago · JSON representation ·

Repository

BAyesian Model-Building Interface (Bambi) in Python.

Basic Info
Statistics
  • Stars: 1,188
  • Watchers: 28
  • Forks: 135
  • Open Issues: 94
  • Releases: 25
Topics
bayesian-inference bayesian-statistics python regression-models statistical-analysis statistical-modeling
Created almost 10 years ago · Last pushed 6 months ago
Metadata Files
Readme Changelog Contributing Funding License Code of conduct Citation Governance

README.md

PyPi version Build Status codecov Code style: black

BAyesian Model-Building Interface in Python

Overview

Bambi is a high-level Bayesian model-building interface written in Python. It's built on top of the PyMC probabilistic programming framework, and is designed to make it extremely easy to fit mixed-effects models common in social sciences settings using a Bayesian approach.

Installation

Bambi requires a working Python interpreter (3.10+). We recommend installing Python and key numerical libraries using the Anaconda Distribution, which has one-click installers available on all major platforms.

Assuming a standard Python environment is installed on your machine (including pip), Bambi itself can be installed in one line using pip:

pip install bambi

Alternatively, if you want the bleeding edge version of the package you can install from GitHub:

pip install git+https://github.com/bambinos/bambi.git

Dependencies

Bambi requires working versions of ArviZ, formulae, NumPy, pandas and PyMC. Dependencies are listed in pyproject.toml and should all be installed by the Bambi installer; no further action should be required.

Examples

In the following two examples we assume the following basic setup

python import arviz as az import bambi as bmb import numpy as np import pandas as pd

Linear regression

A simple fixed effects model is shown in the example below.

```python

Read in a dataset from the package content

data = bmb.load_data("sleepstudy")

See first rows

data.head()

Initialize the fixed effects only model

model = bmb.Model('Reaction ~ Days', data)

Get model description

print(model)

Fit the model using 1000 on each chain

results = model.fit(draws=1000)

Key summary and diagnostic info on the model parameters

az.summary(results)

Use ArviZ to plot the results

az.plot_trace(results) Reaction Days Subject 0 249.5600 0 308 1 258.7047 1 308 2 250.8006 2 308 3 321.4398 3 308 4 356.8519 4 308 Formula: Reaction ~ Days Family: gaussian Link: mu = identity Observations: 180 Priors: target = mu Common-level effects Intercept ~ Normal(mu: 298.5079, sigma: 261.0092) Days ~ Normal(mu: 0.0, sigma: 48.8915)

    Auxiliary parameters
        sigma ~ HalfStudentT(nu: 4.0, sigma: 56.1721)

mean sd hdi3% hdi97% mcsemean mcsesd essbulk esstail rhat Intercept 251.552 6.658 238.513 263.417 0.083 0.059 6491.0 2933.0 1.0 Days 10.437 1.243 8.179 12.793 0.015 0.011 6674.0 3242.0 1.0 Reactionsigma 47.949 2.550 43.363 52.704 0.035 0.025 5614.0 2974.0 1.0 ```

First, we create and build a Bambi Model. Then, the method model.fit() tells the sampler to start running and it returns an InferenceData object, which can be passed to several ArviZ functions such as az.summary() to get a summary of the parameters distribution and sample diagnostics or az.plot_trace() to visualize them.

Logistic regression

In this example we will use a simulated dataset created as shown below.

python data = pd.DataFrame({ "g": np.random.choice(["Yes", "No"], size=50), "x1": np.random.normal(size=50), "x2": np.random.normal(size=50) })

Here we just add the family argument set to "bernoulli" to tell Bambi we are modelling a binary response. By default, it uses a logit link. We can also use some syntax sugar to specify which event we want to model. We just say g['Yes'] and Bambi will understand we want to model the probability of a "Yes" response. But this notation is not mandatory. If we use "g ~ x1 + x2", Bambi will pick one of the events to model and will inform us which one it picked.

python model = bmb.Model("g['Yes'] ~ x1 + x2", data, family="bernoulli") fitted = model.fit()

After this, we can evaluate the model as before.

More

For a more in-depth introduction to Bambi see our Quickstart and check the notebooks in the Examples webpage.

Documentation

The Bambi documentation can be found in the official docs

Citation

If you use Bambi and want to cite it please use

bibtex @article{Capretto2022, title={Bambi: A Simple Interface for Fitting {Bayesian} Linear Models in {Python}}, volume={103}, url={https://www.jstatsoft.org/index.php/jss/article/view/v103i15}, doi={10.18637/jss.v103.i15}, number={15}, journal={Journal of Statistical Software}, author={Capretto, Tom\'{a}s and Piho, Camen and Kumar, Ravin and Westfall, Jacob and Yarkoni, Tal and Martin, Osvaldo A}, year={2022}, pages={129} }

Contributions

Bambi is a community project and welcomes contributions. Additional information can be found in the Contributing Readme.

For a list of contributors see the GitHub contributor page

Donations

If you want to support Bambi financially, you can make a donation to our sister project PyMC.

Code of Conduct

Bambi wishes to maintain a positive community. Additional details can be found in the Code of Conduct

License

MIT License

Owner

  • Name: bambinos
  • Login: bambinos
  • Kind: organization

Citation (CITATION.cff)

cff-version: 1.2.0
message: "If you use this software, please cite it as below."
authors:
  - family-names: "Capretto"
    given-names: "Tomas"
  - family-names: "Piho"
    given-names: "Camen"
  - family-names: "Kumar"
    given-names: "Ravin"
    orcid: https://orcid.org/0000-0003-0501-6098
  - family-names: "Westfall"
    given-names: "Jacob"
    orcid: https://orcid.org/0000-0001-7566-3544
  - family-names: "Yarkoni"
    given-names: "Tal"
    orcid: https://orcid.org/0000-0002-6558-5113
  - family-names: "Martin"
    given-names: "Osvaldo A"
    orcid: https://orcid.org/0000-0001-7419-8978
title: "Bambi: A simple interface for fitting Bayesian linear models in Python"
version: 0.8.0
date-released: 2022-05-18
url: "https://github.com/bambinos/bambi"
preferred-citation:
  type: article
  authors:
    - family-names: "Capretto"
      given-names: "Tomas"
    - family-names: "Piho"
      given-names: "Camen"
    - family-names: "Kumar"
      given-names: "Ravin"
      orcid: https://orcid.org/0000-0003-0501-6098
    - family-names: "Westfall"
      given-names: "Jacob"
      orcid: https://orcid.org/0000-0001-7566-3544
    - family-names: "Yarkoni"
      given-names: "Tal"
      orcid: https://orcid.org/0000-0002-6558-5113
    - family-names: "Martin"
      given-names: "Osvaldo A"
      orcid: https://orcid.org/0000-0001-7419-8978
  doi: "10.18637/jss.v103.i15"
  journal: "Journal of Statistical Software"
  month: 8
  start: 1 # First page number
  end: 29 # Last page number
  title: "Bambi: A simple interface for fitting Bayesian linear models in Python"
  issue: 103
  volume: 15
  year: 2022

GitHub Events

Total
  • Create event: 2
  • Release event: 3
  • Issues event: 40
  • Watch event: 113
  • Delete event: 1
  • Issue comment event: 234
  • Push event: 49
  • Pull request review event: 22
  • Pull request review comment event: 22
  • Pull request event: 63
  • Fork event: 18
Last Year
  • Create event: 2
  • Release event: 3
  • Issues event: 40
  • Watch event: 113
  • Delete event: 1
  • Issue comment event: 234
  • Push event: 49
  • Pull request review event: 22
  • Pull request review comment event: 22
  • Pull request event: 63
  • Fork event: 18

Committers

Last synced: 10 months ago

All Time
  • Total Commits: 775
  • Total Committers: 46
  • Avg Commits per committer: 16.848
  • Development Distribution Score (DDS): 0.737
Past Year
  • Commits: 32
  • Committers: 17
  • Avg Commits per committer: 1.882
  • Development Distribution Score (DDS): 0.688
Top Committers
Name Email Commits
tyarkoni t****i@g****m 204
Tomás Capretto t****o@g****m 188
jake-westfall j****l@g****m 125
Osvaldo Martin a****a@g****m 123
Gabriel Stechschulte 6****e 27
Camen Piho 2****r 18
Camen c****r@g****m 17
Tyler Burch b****1@g****m 12
Ravin Kumar r****e@g****m 6
markgoodhead g****d@g****m 3
julianlheureux 1****x 3
Tanish Yelgoe 1****7 3
Jan Tünnermann j****n@u****e 3
ejolly e****y@g****m 3
Agustina Arroyuelo a****o@g****m 2
Amelio Vazquez-Reina a****a@g****m 2
Boje Deforce 7****e 2
DrEntropy D****y 2
GWeindel g****l@g****m 2
Nathaniel N****F 2
Yann McLatchie 6****e 2
Christine P. Chai s****p@g****m 2
Alex Jones 3****d 1
Camen Piho c****n@g****m 1
Junpeng Lao j****o@u****h 1
kddubey k****3@g****m 1
dependabot[bot] 4****] 1
connorhanafee c****e@g****m 1
Will Dean 5****2 1
Tim Hatch t****m@t****m 1
and 16 more...
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 180
  • Total pull requests: 183
  • Average time to close issues: 5 months
  • Average time to close pull requests: 18 days
  • Total issue authors: 82
  • Total pull request authors: 32
  • Average comments per issue: 3.7
  • Average comments per pull request: 3.74
  • Merged pull requests: 151
  • Bot issues: 0
  • Bot pull requests: 1
Past Year
  • Issues: 30
  • Pull requests: 59
  • Average time to close issues: 19 days
  • Average time to close pull requests: 14 days
  • Issue authors: 22
  • Pull request authors: 16
  • Average comments per issue: 2.0
  • Average comments per pull request: 2.61
  • Merged pull requests: 40
  • Bot issues: 0
  • Bot pull requests: 1
Top Authors
Issue Authors
  • tomicapretto (46)
  • aloctavodia (10)
  • GStechschulte (9)
  • canyon289 (7)
  • digicosmos86 (5)
  • danieltomasz (4)
  • NathanielF (3)
  • jt-lab (3)
  • zwelitunyiswa (3)
  • hxk1633 (3)
  • omrihar (3)
  • zaizibai (2)
  • wenboyu0803 (2)
  • fatihbozdag (2)
  • sepro (2)
Pull Request Authors
  • tomicapretto (68)
  • GStechschulte (36)
  • star1327p (16)
  • aloctavodia (12)
  • speco29 (11)
  • tjburch (11)
  • tanishy7777 (8)
  • julianlheureux (6)
  • jt-lab (4)
  • jgyasu (4)
  • B-Deforce (3)
  • DrEntropy (3)
  • connor-pph (3)
  • NathanielF (3)
  • AlexAndorra (2)
Top Labels
Issue Labels
documentation (21) feature request (18) good first issue (14) enhancement (12) bug (12) Discussion (6) help wanted (3) dependencies (1)
Pull Request Labels
enhancement (4) feature request (3) bug (3) documentation (2) dependencies (2) github_actions (2) help wanted (1)

Packages

  • Total packages: 2
  • Total downloads:
    • pypi 33,537 last-month
  • Total docker downloads: 120
  • Total dependent packages: 4
    (may contain duplicates)
  • Total dependent repositories: 17
    (may contain duplicates)
  • Total versions: 42
  • Total maintainers: 5
pypi.org: bambi

BAyesian Model Building Interface in Python

  • Documentation: https://bambi.readthedocs.io/
  • License: MIT License Copyright (c) 2016 the developers of Bambi Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  • Latest release: 0.15.0
    published about 1 year ago
  • Versions: 30
  • Dependent Packages: 4
  • Dependent Repositories: 14
  • Downloads: 33,537 Last month
  • Docker Downloads: 120
Rankings
Downloads: 2.3%
Dependent packages count: 2.4%
Average: 2.8%
Docker downloads count: 2.9%
Dependent repos count: 3.9%
Last synced: 6 months ago
conda-forge.org: bambi
  • Versions: 12
  • Dependent Packages: 0
  • Dependent Repositories: 3
Rankings
Stargazers count: 13.6%
Dependent repos count: 18.1%
Forks count: 18.3%
Average: 25.4%
Dependent packages count: 51.6%
Last synced: 6 months ago

Dependencies

.github/workflows/publish-docs.yml actions
  • actions/checkout v2 composite
  • actions/setup-python v3 composite
  • peaceiris/actions-gh-pages bbdfb200618d235585ad98e965f4aafc39b4c501 composite
  • r-lib/actions/setup-pandoc v1 composite
.github/workflows/publish-pypi.yml actions
  • actions/checkout v3 composite
  • actions/download-artifact v3 composite
  • actions/setup-python v3 composite
  • actions/upload-artifact v3 composite
.github/workflows/test.yml actions
  • actions/checkout v2 composite
  • codecov/codecov-action v1 composite
  • conda-incubator/setup-miniconda v2 composite
pyproject.toml pypi
  • arviz >=0.12.0
  • formulae >=0.5.0
  • graphviz *
  • numpy >1.22,<1.26.0
  • pandas >=1.0.0
  • pymc >=5.5.0
  • pytensor >=2.12.3
  • scipy >=1.7.0