Coder Social home page Coder Social logo

bayes-demo's Introduction

Bayes Demo

Tool for calculating the posterior probability distribution and marginal likelihood of a parameter from a binomial distribution using a beta prior probability distribution.

Used to compute Figure 1 in "Jamie R. Oaks, Kerry A. Cobb, Vladimir N. Minin, and Adam D. Leaché. 2018. Marginal likelihoods in phylogenetics: a review of methods and applications."

An interactive Javascript implementation is available at https://kerrycobb.github.io/beta-binomial-web-demo/

Installation

pip install git+https://github.com/phyletica/bayes-demo

Usage

Command Line

bayes-demo --help

Python Modules

Examples

Compute and plot single model

Compute probability distributions and marginal likelihood of a single model and plot the probability distributions

import bayes_demo as bd

M = bd.BetaBinomial()

MM = bd.BetaBinomial(a=0.5, b=0.5, n=100, p=0.5)

bd.plot_model(MM)

Output:

Compute and plot multiple models

Compute probability distributions and marginal likelihood of a multiple models and plot the probability distributions and marginal likelihoods of each model

import bayes_demo as bd

inputs = [(1, 1), (0.6, 0.6), (5, 5), (1, 5)]

models = bd.get_models(inputs, n=100, p=0.5)

bd.plot_models(models)

Output:

Documentation

BetaBinomial(a=1, b=1, n=100, p=0.5, params=1000)

Binomial model with a beta prior distribution

Arguments:

  • a: alpha parameter for beta prior distribution, defaults to 1
  • b: beta parameter for beta prior distribution, defaults to 1
  • n: sample size of simulated, defaults to 100
  • p: proportion of successes, defaults to 0.5
  • params: number of parameters to draw from probability density functions

Class attributes:

  • a: alpha shape parameter of model
  • b: beta shape parameter of model
  • n: sample size of model
  • p: proportion success of model
  • x: array between 0 and 1 with length given by params argument
  • like_df: likelihood density function of array x
  • prior_df: prior probability density function of array x
  • post_df: posterior probability density function of array x
  • like: likelihood of model
  • prior: prior probability of model
  • post: posterior probability of model
  • marginal: marginal likelihood of model
get_models(shape_params, n=100, p=0.5, params=1000)

Compute multiple binomial models

Arguments:

  • shape_params: List of tuples containing alpha and beta shape parameters.
    • Example: [(a1, b1), (a2, b2), (a3, b3)]
  • a: alpha parameter for beta prior distribution, defaults to 1
  • b: beta parameter for beta prior distribution, defaults to 1
  • n: sample size of simulated, defaults to 100
  • p: proportion of successes, defaults to 0.5
  • params: number of parameters to draw from probability density functions
plot_model(M, show=True, save=False, format='png')

Plot probability density functions of a binomial model instance

Arguments:

  • M: BetaBinomial class instance
  • show: boolean, show plot, defaults to True
  • save: boolean, save plot to plot.pdf, defaults to False
  • format: output file format, defaults to 'png'
plot_models(models, show=True, save=False, format='png')

Plot probability density functions and marginal likelihoods of multiple models

Arguments:

  • models: list of 4 BetaBinomial model instances
  • show: boolean, show graph, defaults to True
  • save: boolean, save plot to grid-plot.pdf, defaults to False
  • format: output file format, defaults to 'png'

Acknowledgments

This work was made possible by funding provided to Jamie Oaks from the National Science Foundation (DEB 1656004).

License

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

See "LICENSE" for full terms and conditions of usage.

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.