Git Product home page Git Product logo

mcmchammer's Introduction

mcmcHammer

Tools for analysis of MCMC chains

mcmcHammer is just like all the other packages for analyzing MCMC chains from Bayesian analysis, except that it's not. Like the others, it can create trace plots and density plots. But unlike them, it automates "extracting" variables, especially variables with indices. For example, say your set of MCMC chains have variables named beta0, beta1, and beta2, as well as gamma[1, 1], gamma[1, 2], gamma[2, 1] and gamma[2, 2]. You can easily create trace plots and density plots for each of these with minimal "manual" tweaking of variable names. Perforce:

mh_trace(mcmc, 'beta', i=0:2)
mh_density(mcmc, 'gamma', j=1:2, k=1:2)

...will make trace and density plots for the beta variables and the gamma variables. It can even do so if you can't recall how many variants of a variable there are. For example,

mh_trace(mcmc, 'beta', i=TRUE)
mh_density(mcmc, 'gamma', j=TRUE, k=TRUE)

will make trace or density plots for all variables of the pattern beta* and gamma[*, *].

All plots are in ggplot2 package format, so they can be further manipulated using the grammar of graphics tools in that package.

Installation

You can install mcmcHammer from GitHub using:

remotes::install_github('adamlilith/mcmcHammer', dependencies=TRUE)

You may need to install the remotes package first, using:

install.packages('remotes')

Usage

Most function require either an object of class mcmc or mcmc.list, which are often the format of output from modeling functions in Bayesian packages. However, they can also be created by the coda package. Functions in mcmcHammer will need to "stack" mcmc objects before they can be used. Here, a "stack" is the product of simply rbind-ing one mcmc matrix on top of the next. Stacking can be done automatically by each function if the argument stacked is FALSE, but if you are using the functions a lot, it's easier and often much faster to stack the mcmc chains first then use this as the input into functions:

library(mcmcHammer)
data(mcmc)

mcmc_stacked <- mh_stack(mcmc)

Now, we can call summary and diagnostic functions with the stacked version of the MCMC chains:

mh_trace_density(mcmc_stacked, param='beta', i=0:5)
mh_summary_by_param(mcmc_stacked, fun=mean, param='gamma', j=1:2, k=1:2)

If we hadn't stacked the chains, we could still use these functions, albeit with some overhead:

mh_trace_density(mcmc, param='beta', i=0:5, stacked=FALSE)
mh_summary_by_param(mcmc, fun=mean, param='gamma', j=1:2, k=1:2, stacked=FALSE)

Functions

MCMC diagnostics and summaries

  • mh_trace_density: Trace plots and density plots
  • mh_density: Density plots
  • mh_trace: Trace plots
  • mh_summary_by_param: Calculate summary statistics for each variable

MCMC chain manipulation

  • mh_stack: "Stack" multiple MCMC chains on one another

Helper functions

  • mh_param Create variable names with or without indices

Can't touch this.

~ Adam ~

mcmchammer's People

Contributors

adamlilith avatar

Stargazers

 avatar

Watchers

 avatar  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.