Built using Zelig version r packageVersion("Zelig")
knitr::opts_knit$set( stop_on_error = 2L ) knitr::opts_chunk$set( fig.height = 11, fig.width = 7 ) options(cite = FALSE)
rm(list=ls(pattern="\\.out")) suppressWarnings(suppressMessages(library(Zelig))) set.seed(1234)
Zelig has three available diagnostic tests for MCMC models. Here is an example of their use.
First we attach the sample dataset and estimate a linear regression using the MCMC normal.bayes
model:
data(macro) z.out <- zelig(unem ~ gdp + capmob + trade, model = "normal.bayes", data = macro, verbose = FALSE)
You can check for convergence before summarizing the estimates with three diagnostic tests.
The Geweke diagnostic tests the null hypothesis that the Markov chain is in the stationary distribution and produces z-statistics for each estimated parameter.
z.out$geweke.diag()
The Heidelberger and Welch diagnostic first tests the null hypothesis that the Markov Chain is in the stationary distribution and produces p-values for each estimated parameter. Calling this diagnostic also produces output that indicates whether the mean of a marginal posterior distribution can be estimated with sufficient precision, assuming that the Markov Chain is in the stationary distribution.
z.out$heidel.diag()
The Raftery and Lewis diagnostic indicates how long the Markov Chain should run before considering draws from the marginal posterior distributions sufficiently representative of the stationary distribution.
z.out$raftery.diag()
The convergence diagnostics are part of the CODA package by Martyn Plummer, Nicky Best, Kate Cowles, and Karen Vines. Bayesian normal regression is part of the MCMCpack package by Andrew D. Martin and Kevin M. Quinn.
z.out$references()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.