Code Monkey home page Code Monkey logo

bma's Introduction

Bayesian Model Averaging

Provides routines for Bayesian Model Averaging (BMA). BMA searches a model space (e.g. linear regression models) for promising models and computes the posterior probability distribution over that space. Coefficients are then estimated from a weighted average over the model space.

Running BMA is as simple as fitting a regression model. Estimates will be close to the ones you would obtain from fitting the "true" nested model, and no knowledge of that model is required.

TOC

The following scripts are relevant for end users:

  • linear_regression.py contains routines for Bayesian linear regression.
  • linear_averaging.py contains routines for linear BMA.
  • sim.py demonstrates basic usage of linear BMA.

The following scripts are useful if you wish to adapt BMA to other model spaces:

  • core.py contains routines for generic BMA.
  • mcmc.py contains generic MCMC routines.

Usage

The specific Bayesian regression model I use expects 2 hyperparameters:

  • g is a parameter that penalizes model size. I recommend setting it to max(n_obs, n_dim^2).
  • p is your prior expectation of how many relevant variables your dataset contains. If you expected 10% of the variables in X to be relevant, you would set it to 1/10.

Basic usage is demonstrated in sim.py. Given regressors X and response y You can fit the model by executing

mod = linear_averaging.LinearMC3(X, y, g, p)

mod.select()

mod.estimate()

The first step computes the posterior model distribution, the second computes the posterior distributions over the model parameters.

Please consult the docstrings for further documentation.

Dependencies

All scripts were written with Python 3 in mind and require the usual set of scientific Python libraries. They can be converted to Python 2.7 with minimal changes. It is crucial to enable true division by adding the following line to all scripts:

from __future__ import division

References

  • Kass and Wassermann (1995) and Kass and Raftery (1995) for Bayesian model averaging and MC3.
  • Liang et al. (2008) for the Bayesian Linear Regression model.
  • Hastings (1970) for details on the Metropolis-Hastings algorithm.
  • Sokal (1997) for MCMC diagnostics.

bma's People

Contributors

timsf avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.