Skip to main content

bambi model management (bammm)

Estimating complex models can take time. bammm allows one to save estimated models and to later load them as required (without the need to re-estimate them).

Currently it is build to only work with (generalized) linear models in python that have been esimtated using bambi but in essence it can be used to save samples from any PyMC model.

Functionality

  1. Creation and mangement of database of local models (simple JSON file)
  2. Model (dependent variable, fixed and random effects) and estimation parameters (no chains, samples/chain, cores) specification.
  3. Automatic build of regression equation (input to bambi) using mm.geerate_equation()
  4. Model estimation using mm.estimate_lmm()
  5. Saving (mm.save_model_info()) and updating (mm.update_model_entry()) of estimated model information.
  6. Loading previously esimtated model (mm.estimate_lmm())

Usage

Setup

Install using pip:

pip install bammm-ozika

Load

import bammm.bammm as mm

Full example script can be found here.

Generate your local JSON database

Before first use on a project a local database needs to be generated. Specify a path for the database:

os.chdir(root_dir)
db_path = os.path.join( "demo", "my_project", "databse_name.json")

Initialize database:

mm.models_init(db_path)

Fitting a new linear model

Load database

models = json.load(open(db_path, "r"))

Specify linear model. The idea is to have a specific model name and a "group/family" for each model. bammm will create a folder (model_family) and save data of individual models in there using pickle.

# load data that come with bambi
data = bmb.load_data("sleepstudy")

model_family = "sleepstudy" # this will be used as a folder name to host the models
model_identifier = "maximum_model"
# dependent variable
mod["lmm"]["dep_var"] = "Reaction" # Reaction time
# fixed effects
mod["lmm"]["fxeff"] = ["Days"] # longitudinal data set
# random effects
mod["lmm"]["rneff"] = ["Days|Subject"]
# build equation
mod["lmm"]["eq"] = mm.generate_equation(mod["lmm"]["dep_var"], mod["lmm"]["fxeff"], mod["lmm"]["rneff"])

Specify estimation parameters.

# fitting information
mod["est"]["nchains"] = 2
mod["est"]["nsamples"] = 4000
mod["est"]["ncores"] = 2 # number of cores to be useds in fitting

Specify paths and create relevant strings.

mod = mm.prepare_fit(mod, model_family, model_identifier, models_path)
# save model (it's a good idea to load/save the DB often, especially if one runs multiple models at the same time)
models[mod["name"]] = mod
mm.save_model_info(models, db_path)

Estimate model. This also automatically saves the data to the location specified in models_path

mod, results, m = mm.estimate_lmm(mod, data, override=0)
mm.update_model_entry(models, mod, db_path)

Load previously fitted model

It is rather simple

# load database
models = json.load(open(db_path, "r"))
model_name = "sleepstudy_maximum_model_2_4000" # model estimated above
mod = models[model_name]
# load model
mod, results, m = mm.estimate_lmm(mod, [], override=0)

This might not be the best way to achieve model saving/loading, but it seems to work well (at least for the poor practitioner of statistics that is me).

Metadata

Release files for bammm-ozika 0.0.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bammm-ozika 0.0.8
File Size Uploaded Provenance
bammm-ozika-0.0.8.tar.gz 4.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for bammm-ozika 0.0.8
File Interpreter ABI Platform
bammm_ozika-0.0.8-py3-none-any.whl Python 3 none any Details

Total release size: 10.7 kB

Release files / bammm-ozika-0.0.8.tar.gz

Download URL bammm-ozika-0.0.8.tar.gz
Size 4.8 kB
Tags Source
SHA-256 checksum
How to use checksums
fe4f3ca740c52ff1006a0dc85bc57aef17f1e34a987d68696e29f6d085010cd0
BLAKE2b-256 checksum
How to use checksums
f6786930abbfb50312d3f6dbbf6dc13ddb24cbd1bff9096d8fa4456f132ee526
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.7.3

Release files / bammm_ozika-0.0.8-py3-none-any.whl

Download URL bammm_ozika-0.0.8-py3-none-any.whl
Size 5.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e57f225f0511a133966e749976d23a18b8b78c1dd88f5ed4de8246a36cc27ea8
BLAKE2b-256 checksum
How to use checksums
dbded49acefb8de1fb5bd90576d07a5c2937b04a7efa97059ecd58a17d4a3110
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.7.3

Security for bammm-ozika 0.0.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page