<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/check-your-prior-posterior-overlap-ppo-mcmc-wrangling-in-r-made-easy-with-mcmcvis/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://lynchlab.com/2018/01/18/check-your-prior-posterior-overlap-ppo-mcmc-wrangling-in-r-made-easy-with-mcmcvis/"> R – Lynch Lab</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<div>
When fitting a Bayesian model using MCMC (often via JAGS/BUGS/Stan), a number of checks are typically performed to make sure your model is worth interpreting without further manipulation (remember: <a rel="nofollow" href="https://en.wikipedia.org/wiki/All_models_are_wrong" target="_blank">all models are wrong, some are useful!</a>):
<ul>
<li><strong>R-hat (AKA Gelman-Rubin statistic)</strong> – used to assess convergence of chains in the model</li>
<li><strong>Visual assessment of chains</strong> – used to assess whether posterior chains mixed well (convergence)</li>
<li><strong>Visual assessment of posterior distribution shape</strong> – used to determine if the posterior distribution is constrained</li>
<li><strong>Posterior predictive check (predicting data using estimated parameters)</strong> – used to make sure that the model can generate the data used in the model</li>
</ul>
<div>
<h2>PPO</h2>
<p>One check, however, is often missing: <strong>a robust assessment of the degree to which the prior is informing the posterior distribution</strong>. Substantial influence of the prior on the posterior may not be apparent through the use of R-hat and visual checks alone. Version 0.9.2 of <code>MCMCvis</code> (<a rel="nofollow" href="https://cran.r-project.org/package=MCMCvis" target="_blank">now available on CRAN</a>), makes quantifying and plotting the prior posterior overlap (PPO) simple.</p>
<p><code>MCMCvis</code> is an R package designed to streamline analysis of Bayesian model results derived from MCMC samplers (e.g., JAGS, BUGS, Stan). It can be used to easily visualize, manipulate, and summarize MCMC output. The newest version is full of new features – a full tutorial can be found <a rel="nofollow" href="http://www.caseyyoungflesh.com/software/" target="_blank">here</a>.</p>
</div>
<div>
<h2>An example</h2>
<p>To check PPO for a model, we will use the function <code>MCMCtrace</code>. As the function is used to generate trace and density plots, checking for PPO is barely more work than just doing the routine checks that one would ordinarily perform. The function plots trace plots on the left and density plots for both the posterior (black) and prior (red) distributions on the right. The function calculates the percent overlap between the prior and posterior and prints this value on the plot. See <code>?MCMCtrace</code> in R for details regarding the syntax.</p>
<pre><code>#install package
install.packages('MCMCvis', repos = &quot;http://cran.case.edu&quot;)

#load package
require(MCMCvis)

#load example data
data(MCMC_data)

#simulate data from the prior used in your model
#number of iterations should equal the number of draws times the number of chains (although the function will adjust if the correct number of iterations is not specified)
#in JAGS: parameter ~ dnorm(0, 0.001)
PR &lt;- rnorm(15000, 0, 32)

#run the function for just beta parameters
MCMCtrace(MCMC_data, params = 'beta', priors = PR, pdf = FALSE)</code></pre>
</div>
<div>
<h2><img data-orig-file="https://lynchlab.files.wordpress.com/2018/01/unnamed-chunk-1-1.png?w=456" data-orig-size="672,480" data-medium-file="https://lynchlab.files.wordpress.com/2018/01/unnamed-chunk-1-1.png?w=456?w=300" data-attachment-id="1174" data-image-meta="{" data-image-description="" src="https://lynchlab.files.wordpress.com/2018/01/unnamed-chunk-1-1.png?w=456" data-permalink="https://lynchlab.com/2018/01/18/check-your-prior-posterior-overlap-ppo-mcmc-wrangling-in-r-made-easy-with-mcmcvis/unnamed-chunk-1-1/" data-large-file="https://lynchlab.files.wordpress.com/2018/01/unnamed-chunk-1-1.png?w=456?w=584" alt="unnamed-chunk-1-1" data-image-title="unnamed-chunk-1-1" sizes="(max-width: 584px) 100vw, 584px" data-comments-opened="0" class="wp-image-1174" data-recalc-dims="1"></h2>
<h2>Why check?</h2>
<p>Checking the PPO has particular utility when trying to determine if the parameters in your model are identifiable. If substantial PPO exists, the prior may simply be dictating the posterior distribution – the data may have little influence on the results. If a small degree of PPO exists, the data was informative enough to overcome the influence of the prior. In the field of ecology, nonidentifiability is a particular concern in some types of mark-recapture models. <a rel="nofollow" href="https://scholar.google.com/scholar?hl=en&as_sdt=0%2C33&q=Weak+identifiability+in+models+for+mark-recapture-recovery+data&btnG=" target="_blank">Gimenez (2009)</a> developed quantitative guidelines to determine when parameters are robustly identifiable using PPO.</p>
<p>While a large degree of PPO is not always a bad thing (e.g., substantial prior knowledge about the system may result in very informative priors used in the model), it is important to know where data was and was not informative for parameter estimation. The degree of PPO that is acceptable for a particular model will depend on a great number of factors, and may be somewhat subjective (but see Gimenez [2009] for a less subjective case). Like other checks, PPO is just one of many tools to be used for model assessment. Finding substantial PPO when unexpected may suggest that further model manipulation is needed. Happy model building!</p>
</div>
<div>
<h2>Other <code>MCMCvis</code> improvements</h2>
<p>Check out the rest of the <a rel="nofollow" href="http://www.caseyyoungflesh.com/software/" target="_blank">new package freatures</a>, including the option to calculate the number of effective samples for each parameter, ability to take arguments in the form of a ‘regular expression’ for the <code>params</code> argument, ability to retain the structure of all parameters in model output (e.g., parameters specified as matrices in the model are summarized as matrices).</p>
</div>
<div>
<h2>Follow <a rel="nofollow" href="http://www.caseyyoungflesh.com/" target="_blank">Casey Youngflesh</a> on Twitter <a rel="nofollow" href="https://twitter.com/caseyyoungflesh" target="_blank">@caseyyoungflesh</a>. The <code>MCMCvis</code> source code can be found on <a rel="nofollow" href="https://github.com/caseyyoungflesh/MCMCvis" target="_blank">GitHub</a>.</h2>
</div>
</div>
<p></p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://lynchlab.com/2018/01/18/check-your-prior-posterior-overlap-ppo-mcmc-wrangling-in-r-made-easy-with-mcmcvis/"> R – Lynch Lab</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/I4NMNIcklvQ" height="1"></a></div>